_id stringlengths 2 7 | title stringlengths 1 88 | partition stringclasses 3
values | text stringlengths 31 13.1k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q249400 | dummynum | train | def dummynum(character, name):
"""Count how many nodes there already are in the character whose name
starts the same.
"""
num = 0
for nodename in character.node:
nodename = str(nodename)
if not nodename.startswith(name):
continue
| python | {
"resource": ""
} |
q249401 | lru_append | train | def lru_append(kc, lru, kckey, maxsize):
"""Delete old data from ``kc``, then add the new ``kckey``.
:param kc: a three-layer keycache
:param lru: an :class:`OrderedDict` with a key for each triple that should fill out ``kc``'s three layers
:param kckey: a triple that indexes into ``kc``, which will be... | python | {
"resource": ""
} |
q249402 | Cache.load | train | def load(self, data):
"""Add a bunch of data. Must be in chronological order.
But it doesn't need to all be from the same branch, as long as
each branch is chronological of itself.
"""
branches = defaultdict(list)
for row in data:
branches[row[-4]].append(ro... | python | {
"resource": ""
} |
q249403 | Cache._valcache_lookup | train | def _valcache_lookup(self, cache, branch, turn, tick):
"""Return the value at the given time in ``cache``"""
if branch in cache:
branc = cache[branch]
try:
if turn in branc and branc[turn].rev_gettable(tick):
return branc[turn][tick]
... | python | {
"resource": ""
} |
q249404 | Cache._get_keycache | train | def _get_keycache(self, parentity, branch, turn, tick, *, forward):
"""Get a frozenset of keys that exist in the entity at the moment.
With ``forward=True``, enable an optimization that copies old key sets
forward and updates them.
"""
lru_append(self.keycache, self._kc_lru, (p... | python | {
"resource": ""
} |
q249405 | Cache._update_keycache | train | def _update_keycache(self, *args, forward):
"""Add or remove a key in the set describing the keys that exist."""
entity, key, branch, turn, tick, value = args[-6:]
parent = args[:-6]
kc = self._get_keycache(parent + (entity,), branch, turn, tick, forward=forward)
if value is None... | python | {
"resource": ""
} |
q249406 | Cache.remove | train | def remove(self, branch, turn, tick):
"""Delete all data from a specific tick"""
time_entity, parents, branches, keys, settings, presettings, remove_keycache, send = self._remove_stuff
parent, entity, key = time_entity[branch, turn, tick]
branchkey = parent + (entity, key)
keykey... | python | {
"resource": ""
} |
q249407 | Cache._remove_keycache | train | def _remove_keycache(self, entity_branch, turn, tick):
"""Remove the future of a given entity from a branch in the keycache"""
keycache = self.keycache
if entity_branch in keycache:
kc = keycache[entity_branch]
if turn in kc:
kcturn = kc[turn]
... | python | {
"resource": ""
} |
q249408 | Cache.count_entities_or_keys | train | def count_entities_or_keys(self, *args, forward=None):
"""Return the number of keys an entity has, if you specify an entity.
Otherwise return the number of entities.
"""
if forward is None:
| python | {
"resource": ""
} |
q249409 | EdgesCache._adds_dels_sucpred | train | def _adds_dels_sucpred(self, cache, branch, turn, tick, *, stoptime=None):
"""Take the successors or predecessors cache and get nodes added or deleted from it
Operates like ``_get_adds_dels``.
"""
added = set()
deleted = set()
for node, nodes in cache.items():
| python | {
"resource": ""
} |
q249410 | EdgesCache._get_destcache | train | def _get_destcache(self, graph, orig, branch, turn, tick, *, forward):
"""Return a set of destination nodes succeeding ``orig``"""
destcache, destcache_lru, get_keycachelike, successors, adds_dels_sucpred = self._get_destcache_stuff
lru_append(destcache, destcache_lru, ((graph, orig, branch), tu... | python | {
"resource": ""
} |
q249411 | EdgesCache._get_origcache | train | def _get_origcache(self, graph, dest, branch, turn, tick, *, forward):
"""Return a set of origin nodes leading to ``dest``"""
origcache, origcache_lru, get_keycachelike, predecessors, adds_dels_sucpred = self._get_origcache_stuff
lru_append(origcache, origcache_lru, ((graph, dest, branch), turn,... | python | {
"resource": ""
} |
q249412 | EdgesCache.iter_successors | train | def iter_successors(self, graph, orig, branch, turn, tick, *, forward=None):
"""Iterate over successors of a given origin node at a given time."""
if self.db._no_kc:
yield from self._adds_dels_sucpred(self.successors[graph, orig], branch, turn, tick)[0]
return
| python | {
"resource": ""
} |
q249413 | EdgesCache.iter_predecessors | train | def iter_predecessors(self, graph, dest, branch, turn, tick, *, forward=None):
"""Iterate over predecessors to a given destination node at a given time."""
if self.db._no_kc:
yield from self._adds_dels_sucpred(self.predecessors[graph, dest], branch, turn, tick)[0]
return
| python | {
"resource": ""
} |
q249414 | EdgesCache.has_successor | train | def has_successor(self, graph, orig, dest, branch, turn, tick, *, forward=None):
"""Return whether an edge connects the origin to the destination at the given time.
Doesn't require the edge's index, which makes it slower than retrieving a
particular edge.
"""
| python | {
"resource": ""
} |
q249415 | EdgesCache.has_predecessor | train | def has_predecessor(self, graph, dest, orig, branch, turn, tick, *, forward=None):
"""Return whether an edge connects the destination to the origin at the given time.
Doesn't require the edge's index, which makes it slower than retrieving a
particular edge.
"""
| python | {
"resource": ""
} |
q249416 | Spot.push_pos | train | def push_pos(self, *args):
"""Set my current position, expressed as proportions of the board's
width and height, into the ``_x`` and ``_y`` keys of the
entity in my ``proxy`` property, such that it will be
recorded in the database.
| python | {
"resource": ""
} |
q249417 | convert_to_networkx_graph | train | def convert_to_networkx_graph(data, create_using=None, multigraph_input=False):
"""Convert an AllegedGraph to the corresponding NetworkX graph type."""
if isinstance(data, AllegedGraph):
result = networkx.convert.from_dict_of_dicts(
| python | {
"resource": ""
} |
q249418 | AllegedMapping.connect | train | def connect(self, func):
"""Arrange to call this function whenever something changes here.
The arguments will be this object, the key changed, and the value set.
| python | {
"resource": ""
} |
q249419 | AllegedMapping.disconnect | train | def disconnect(self, func):
"""No longer call the function when something changes here."""
if id(self) not in _alleged_receivers:
return
l = _alleged_receivers[id(self)]
try:
| python | {
"resource": ""
} |
q249420 | AllegedMapping.send | train | def send(self, sender, **kwargs):
"""Internal. Call connected functions."""
if id(self) not in _alleged_receivers:
return
| python | {
"resource": ""
} |
q249421 | AllegedMapping.update | train | def update(self, other, **kwargs):
"""Version of ``update`` that doesn't clobber the database so much"""
from itertools import chain
if hasattr(other, 'items'):
other = other.items()
for (k, v) in chain(other, kwargs.items()):
| python | {
"resource": ""
} |
q249422 | AllegedGraph.clear | train | def clear(self):
"""Remove all nodes and edges from the graph.
Unlike the regular networkx implementation, this does *not*
remove the graph's name. But all the other graph, | python | {
"resource": ""
} |
q249423 | DiGraph.remove_edges_from | train | def remove_edges_from(self, ebunch):
"""Version of remove_edges_from that's much like normal networkx but only
deletes once, since the database doesn't keep separate adj and
succ mappings
"""
for | python | {
"resource": ""
} |
q249424 | DiGraph.add_edge | train | def add_edge(self, u, v, attr_dict=None, **attr):
"""Version of add_edge that only writes to the database once"""
if attr_dict is None:
attr_dict = attr
else:
try:
attr_dict.update(attr)
except AttributeError:
raise NetworkXErro... | python | {
"resource": ""
} |
q249425 | DiGraph.add_edges_from | train | def add_edges_from(self, ebunch, attr_dict=None, **attr):
"""Version of add_edges_from that only writes to the database once"""
if attr_dict is None:
attr_dict = attr
else:
try:
attr_dict.update(attr)
except AttributeError:
rais... | python | {
"resource": ""
} |
q249426 | MultiDiGraph.add_edge | train | def add_edge(self, u, v, key=None, attr_dict=None, **attr):
"""Version of add_edge that only writes to the database once."""
if attr_dict is None:
attr_dict = attr
else:
try:
attr_dict.update(attr)
except AttributeError:
raise N... | python | {
"resource": ""
} |
q249427 | Place.delete | train | def delete(self):
"""Remove myself from the world model immediately."""
| python | {
"resource": ""
} |
q249428 | NodeMapProxy.patch | train | def patch(self, patch):
"""Change a bunch of node stats at once.
This works similarly to ``update``, but only accepts a dict-like argument,
and it recurses one level.
The patch is sent to the LiSE core all at once, so this is faster than
using ``update``, too.
:param p... | python | {
"resource": ""
} |
q249429 | EngineProxy.handle | train | def handle(self, cmd=None, **kwargs):
"""Send a command to the LiSE core.
The only positional argument should be the name of a
method in :class:``EngineHandle``. All keyword arguments
will be passed to it, with the exceptions of
``cb``, ``branching``, and ``silent``.
Wi... | python | {
"resource": ""
} |
q249430 | EngineProxy.pull | train | def pull(self, chars='all', cb=None, block=True):
"""Update the state of all my proxy objects from the real objects."""
if block:
deltas = self.handle('get_char_deltas', chars=chars)
self._upd_caches(deltas)
| python | {
"resource": ""
} |
q249431 | EngineProxy.time_travel | train | def time_travel(self, branch, turn, tick=None, chars='all', cb=None, block=True):
"""Move to a different point in the timestream.
Needs ``branch`` and ``turn`` arguments. The ``tick`` is optional; if unspecified,
you'll travel to the last tick in the turn.
May take a callback function ... | python | {
"resource": ""
} |
q249432 | NodeContentsCache.truncate_loc | train | def truncate_loc(self, character, location, branch, turn, tick):
"""Remove future data about a particular location
Return True if I deleted anything, False otherwise.
"""
r = False
branches_turns = self.branches[character, location][branch]
branches_turns.truncate(turn)... | python | {
"resource": ""
} |
q249433 | StatScreen.new_stat | train | def new_stat(self):
"""Look at the key and value that the user has entered into the stat
configurator, and set them on the currently selected
entity.
"""
key = self.ids.newstatkey.text
value = self.ids.newstatval.text
if not (key and value):
# TODO im... | python | {
"resource": ""
} |
q249434 | PawnSpot.on_touch_move | train | def on_touch_move(self, touch):
"""If I'm being dragged, move to follow the touch."""
if touch.grab_current is not self:
| python | {
"resource": ""
} |
q249435 | PawnSpot.finalize | train | def finalize(self, initial=True):
"""Call this after you've created all the PawnSpot you need and are ready to add them to the board."""
if getattr(self, '_finalized', False):
return
if (
self.proxy is None or
not hasattr(self.proxy, 'name')
):... | python | {
"resource": ""
} |
q249436 | normalize_layout | train | def normalize_layout(l):
"""Make sure all the spots in a layout are where you can click.
Returns a copy of the layout with all spot coordinates are
normalized to within (0.0, 0.98).
"""
xs = []
ys = []
ks = []
for (k, (x, y)) in l.items():
xs.append(x)
ys.append(y)
... | python | {
"resource": ""
} |
q249437 | Board.on_touch_down | train | def on_touch_down(self, touch):
"""Check for collisions and select an appropriate entity."""
if hasattr(self, '_lasttouch') and self._lasttouch == touch:
return
if not self.collide_point(*touch.pos):
return
touch.push()
touch.apply_transform_2d(self.to_loc... | python | {
"resource": ""
} |
q249438 | Board.on_touch_move | train | def on_touch_move(self, touch):
"""If an entity is selected, drag it."""
if hasattr(self, '_lasttouch') and self._lasttouch == touch:
return
if self.app.selection in self.selection_candidates:
self.selection_candidates.remove(self.app.selection)
if self.app.select... | python | {
"resource": ""
} |
q249439 | Board.portal_touch_up | train | def portal_touch_up(self, touch):
"""Try to create a portal between the spots the user chose."""
try:
# If the touch ended upon a spot, and there isn't
# already a portal between the origin and this
# destination, create one.
destspot = next(self.spots_at(... | python | {
"resource": ""
} |
q249440 | Board.on_touch_up | train | def on_touch_up(self, touch):
"""Delegate touch handling if possible, else select something."""
if hasattr(self, '_lasttouch') and self._lasttouch == touch:
return
self._lasttouch = touch
touch.push()
touch.apply_transform_2d(self.to_local)
if hasattr(self, 'p... | python | {
"resource": ""
} |
q249441 | Board.on_parent | train | def on_parent(self, *args):
"""Create some subwidgets and trigger the first update."""
if not self.parent or hasattr(self, '_parented'):
return
if not self.wallpaper_path:
Logger.debug("Board: waiting for wallpaper_path")
Clock.schedule_once(self.on_parent, 0)... | python | {
"resource": ""
} |
q249442 | Board.update | train | def update(self, *args):
"""Force an update to match the current state of my character.
This polls every element of the character, and therefore
causes me to sync with the LiSE core for a long time. Avoid
when possible.
"""
# remove widgets that don't represent anythin... | python | {
"resource": ""
} |
q249443 | Board.update_from_delta | train | def update_from_delta(self, delta, *args):
"""Apply the changes described in the dict ``delta``."""
for (node, extant) in delta.get('nodes', {}).items():
if extant:
if node in delta.get('node_val', {}) \
and 'location' in delta['node_val'][node]\
... | python | {
"resource": ""
} |
q249444 | Board.arrows | train | def arrows(self):
"""Iterate over all my arrows."""
for o in self.arrow.values():
| python | {
"resource": ""
} |
q249445 | Board.pawns_at | train | def pawns_at(self, x, y):
"""Iterate over pawns that collide the given point."""
for pawn in self.pawn.values():
| python | {
"resource": ""
} |
q249446 | Board.spots_at | train | def spots_at(self, x, y):
"""Iterate over spots that collide the given point."""
for spot in self.spot.values():
| python | {
"resource": ""
} |
q249447 | Board.arrows_at | train | def arrows_at(self, x, y):
"""Iterate over arrows that collide the given point."""
for arrow in self.arrows():
| python | {
"resource": ""
} |
q249448 | BoardScatterPlane.spot_from_dummy | train | def spot_from_dummy(self, dummy):
"""Make a real place and its spot from a dummy spot.
Create a new :class:`board.Spot` instance, along with the
underlying :class:`LiSE.Place` instance, and give it the name,
position, and imagery of the provided dummy.
"""
(x, y) = self... | python | {
"resource": ""
} |
q249449 | BoardScatterPlane.pawn_from_dummy | train | def pawn_from_dummy(self, dummy):
"""Make a real thing and its pawn from a dummy pawn.
Create a new :class:`board.Pawn` instance, along with the
underlying :class:`LiSE.Place` instance, and give it the name,
location, and imagery of the provided dummy.
"""
dummy.pos = s... | python | {
"resource": ""
} |
q249450 | BoardScatterPlane.arrow_from_wid | train | def arrow_from_wid(self, wid):
"""Make a real portal and its arrow from a dummy arrow.
This doesn't handle touch events. It takes a widget as its
argument: the one the user has been dragging to indicate where
they want the arrow to go. Said widget ought to be invisible.
It check... | python | {
"resource": ""
} |
q249451 | sort_set | train | def sort_set(s):
"""Return a sorted list of the contents of a set
This is intended to be used to iterate over world state, where you just need keys
to be in some deterministic order, but the sort order should be obvious from the key.
Non-strings come before strings and then tuples. Tuples compare elem... | python | {
"resource": ""
} |
q249452 | Portal.reciprocal | train | def reciprocal(self):
"""If there's another Portal connecting the same origin and
destination that I do, but going the opposite way, return
it. Else raise KeyError.
"""
try:
| python | {
"resource": ""
} |
q249453 | Portal.update | train | def update(self, d):
"""Works like regular update, but only actually updates when the new
value and the old value differ. This is necessary to prevent
certain infinite loops.
:arg d: a dictionary
| python | {
"resource": ""
} |
q249454 | CharMenu.toggle_rules | train | def toggle_rules(self, *args):
"""Display or hide the view for constructing rules out of cards."""
if self.app.manager.current != 'rules' and not isinstance(self.app.selected_proxy, CharStatProxy):
self.app.rules.entity = self.app.selected_proxy
self.app.rules.rulebook = self.app... | python | {
"resource": ""
} |
q249455 | CharMenu.toggle_spot_cfg | train | def toggle_spot_cfg(self):
"""Show the dialog where you select graphics and a name for a place,
or hide it if already showing.
"""
if self.app.manager.current == 'spotcfg':
dummyplace = self.screendummyplace
self.ids.placetab.remove_widget(dummyplace)
... | python | {
"resource": ""
} |
q249456 | CharMenu.toggle_pawn_cfg | train | def toggle_pawn_cfg(self):
"""Show or hide the pop-over where you can configure the dummy pawn"""
if self.app.manager.current == 'pawncfg':
dummything = self.app.dummything
self.ids.thingtab.remove_widget(dummything)
dummything.clear()
if self.app.pawncfg.... | python | {
"resource": ""
} |
q249457 | dict_delta | train | def dict_delta(old, new):
"""Return a dictionary containing the items of ``new`` that are either
absent from ``old`` or whose values are different; as well as the
value ``None`` for those keys that are present in ``old``, but
absent from ``new``.
Useful for describing changes between two versions o... | python | {
"resource": ""
} |
q249458 | EngineHandle.character_copy | train | def character_copy(self, char):
"""Return a dictionary describing character ``char``."""
ret = self.character_stat_copy(char)
chara = self._real.character[char]
nv = self.character_nodes_stat_copy(char)
if nv:
ret['node_val'] = nv
ev = self.character_portals_s... | python | {
"resource": ""
} |
q249459 | EngineHandle.character_delta | train | def character_delta(self, char, *, store=True):
"""Return a dictionary of changes to ``char`` since previous call."""
ret = self.character_stat_delta(char, store=store)
nodes = self.character_nodes_delta(char, store=store)
chara = self._real.character[char]
if nodes:
... | python | {
"resource": ""
} |
q249460 | EngineHandle.node_stat_copy | train | def node_stat_copy(self, node_or_char, node=None):
"""Return a node's stats, prepared for pickling, in a dictionary."""
if node is None:
node = node_or_char
else:
node = self._real.character[node_or_char].node[node]
return {
k: v.unwrap() if hasattr(v,... | python | {
"resource": ""
} |
q249461 | EngineHandle.node_stat_delta | train | def node_stat_delta(self, char, node, *, store=True):
"""Return a dictionary describing changes to a node's stats since the
last time you looked at it.
Deleted keys have the value ``None``. If the node's been deleted, this
returns ``None``.
"""
try:
| python | {
"resource": ""
} |
q249462 | EngineHandle.character_nodes_stat_delta | train | def character_nodes_stat_delta(self, char, *, store=True):
"""Return a dictionary of ``node_stat_delta`` output for each node in a
character.
"""
r = {}
nodes = set(self._real.character[char].node.keys())
for node in nodes:
delta = self.node_stat_delta(char, ... | python | {
"resource": ""
} |
q249463 | EngineHandle.update_node | train | def update_node(self, char, node, patch):
"""Change a node's stats according to a dictionary.
The ``patch`` dictionary should hold the new values of stats,
keyed by the stats' names; a value of ``None`` deletes the
stat.
"""
character = self._real.character[char]
| python | {
"resource": ""
} |
q249464 | EngineHandle.update_nodes | train | def update_nodes(self, char, patch, backdate=False):
"""Change the stats of nodes in a character according to a
dictionary.
"""
if backdate:
parbranch, parrev = self._real._parentbranch_rev.get(
| python | {
"resource": ""
} |
q249465 | EngineHandle.del_node | train | def del_node(self, char, node):
"""Remove a node from a character."""
del self._real.character[char].node[node]
for cache in (
self._char_nodes_rulebooks_cache,
self._node_stat_cache,
self._node_successors_cache
):
try:
... | python | {
"resource": ""
} |
q249466 | EngineHandle.thing_travel_to | train | def thing_travel_to(self, char, thing, dest, weight=None, graph=None):
"""Make something find a path to ``dest`` and follow it.
Optional argument ``weight`` is the portal stat to | python | {
"resource": ""
} |
q249467 | StatRowListItemContainer.remake | train | def remake(self, *args):
"""Replace any existing child widget with the one described by my ``config``.
This doesn't need arguments, but accepts any positional arguments provided,
so that you can use this in kvlang
"""
if not self.config:
return
if not all((s... | python | {
"resource": ""
} |
q249468 | BaseStatListView.del_key | train | def del_key(self, k):
"""Delete the key and any configuration for it"""
if k not in self.mirror:
| python | {
"resource": ""
} |
q249469 | BaseStatListView.set_value | train | def set_value(self, k, v):
"""Set a value on the proxy, parsing it to a useful datatype if possible"""
from ast import literal_eval
if self.engine is None or self.proxy is None:
| python | {
"resource": ""
} |
q249470 | BaseStatListView.set_config | train | def set_config(self, key, option, value):
"""Set a configuration option for a key"""
if '_config' not in self.proxy:
newopt = dict(default_cfg)
newopt[option] = value
self.proxy['_config'] = {key: newopt}
else:
if key in | python | {
"resource": ""
} |
q249471 | BaseStatListView.set_configs | train | def set_configs(self, key, d):
"""Set the whole configuration for a key"""
if '_config' in self.proxy:
| python | {
"resource": ""
} |
q249472 | BaseStatListView.iter_data | train | def iter_data(self):
"""Iterate over key-value pairs that are really meant to be displayed"""
for (k, v) in self.proxy.items():
if (
| python | {
"resource": ""
} |
q249473 | BaseStatListView.munge | train | def munge(self, k, v):
"""Turn a key and value into a dictionary describing a widget to show"""
if '_config' in self.proxy and k in self.proxy['_config']:
config = self.proxy['_config'][k].unwrap()
else:
config = default_cfg
return {
'key': k,
... | python | {
"resource": ""
} |
q249474 | BaseStatListView.upd_data | train | def upd_data(self, *args):
"""Update to match new entity data"""
data = [self.munge(k, v) for | python | {
"resource": ""
} |
q249475 | GameScreen.wait_travel | train | def wait_travel(self, character, thing, dest, cb=None):
"""Schedule a thing to travel someplace, then wait for it to finish.
:param character: name of the character
:param thing: name of the thing that will travel
:param dest: name of the place it will travel to
:param cb: callb... | python | {
"resource": ""
} |
q249476 | GameScreen.wait_command | train | def wait_command(self, start_func, turns=1, end_func=None):
"""Call ``start_func``, wait ``turns``, and then call ``end_func`` if provided
Disables input for the duration.
:param start_func: function to call just after disabling input
:param turns: number of turns to wait
:para... | python | {
"resource": ""
} |
q249477 | GameApp.wait_travel | train | def wait_travel(self, character, thing, dest, cb=None):
"""Schedule a thing to travel someplace, then wait for it to finish, and call ``cb`` if provided
:param character: name of the character
:param thing: name of the thing
:param dest: name of the destination (a place)
| python | {
"resource": ""
} |
q249478 | RuleButton.on_state | train | def on_state(self, *args):
"""If I'm pressed, unpress all other buttons in the ruleslist"""
# This really ought to be done with the selection behavior
if self.state == 'down':
self.rulesview.rule = self.rule
| python | {
"resource": ""
} |
q249479 | RulesList.on_rulebook | train | def on_rulebook(self, *args):
"""Make sure to update when the rulebook changes"""
| python | {
"resource": ""
} |
q249480 | RulesList.redata | train | def redata(self, *args):
"""Make my data represent what's in my rulebook right now"""
if self.rulesview is None:
Clock.schedule_once(self.redata, 0)
return
data = [
| python | {
"resource": ""
} |
q249481 | RulesView.on_rule | train | def on_rule(self, *args):
"""Make sure to update when the rule changes"""
if self.rule is None:
| python | {
"resource": ""
} |
q249482 | RulesView.finalize | train | def finalize(self, *args):
"""Add my tabs"""
if not self.canvas:
Clock.schedule_once(self.finalize, 0)
return
deck_builder_kwargs = {
'pos_hint': {'x': 0, 'y': 0},
'starting_pos_hint': {'x': 0.05, 'top': 0.95},
'card_size_hint': (0.3, ... | python | {
"resource": ""
} |
q249483 | RulesView.get_functions_cards | train | def get_functions_cards(self, what, allfuncs):
"""Return a pair of lists of Card widgets for used and unused functions.
:param what: a string: 'trigger', 'prereq', or 'action'
:param allfuncs: a sequence of functions' (name, sourcecode, signature)
"""
if not self.rule:
... | python | {
"resource": ""
} |
q249484 | RulesView.set_functions | train | def set_functions(self, what, allfuncs):
"""Set the cards in the ``what`` builder to ``allfuncs``
:param what: a string, 'trigger', 'prereq', or 'action'
| python | {
"resource": ""
} |
q249485 | RulesView._upd_unused | train | def _upd_unused(self, what):
"""Make sure to have exactly one copy of every valid function in the
"unused" pile on the right.
Doesn't read from the database.
:param what: a string, 'trigger', 'prereq', or 'action'
"""
builder = getattr(self, '_{}_builder'.format(what))... | python | {
"resource": ""
} |
q249486 | Rule._fun_names_iter | train | def _fun_names_iter(self, functyp, val):
"""Iterate over the names of the functions in ``val``,
adding them to ``funcstore`` if they are missing;
or if the items in ``val`` are already the names of functions
in ``funcstore``, iterate over those.
"""
funcstore = getattr(s... | python | {
"resource": ""
} |
q249487 | Rule.duplicate | train | def duplicate(self, newname):
"""Return a new rule that's just like this one, but under a new
name.
"""
if self.engine.rule.query.haverule(newname):
raise KeyError("Already have a rule called {}".format(newname))
return Rule(
| python | {
"resource": ""
} |
q249488 | AllRules.new_empty | train | def new_empty(self, name):
"""Make a new rule with no actions or anything, and return it."""
if name in self:
raise KeyError("Already have rule {}".format(name))
| python | {
"resource": ""
} |
q249489 | slow_iter_turns_eval_cmp | train | def slow_iter_turns_eval_cmp(qry, oper, start_branch=None, engine=None):
"""Iterate over all turns on which a comparison holds.
This is expensive. It evaluates the query for every turn in history.
"""
def mungeside(side):
if isinstance(side, Query):
return side.iter_turns
e... | python | {
"resource": ""
} |
q249490 | MenuTextInput.on_enter | train | def on_enter(self, *args):
"""Call the setter and blank myself out so that my hint text shows
up. It will be the same you just entered if everything's
working.
"""
if self.text == '': | python | {
"resource": ""
} |
q249491 | MenuIntInput.insert_text | train | def insert_text(self, s, from_undo=False):
"""Natural numbers only."""
return super().insert_text(
| python | {
"resource": ""
} |
q249492 | AbstractCharacter.do | train | def do(self, func, *args, **kwargs):
"""Apply the function to myself, and return myself.
Look up the function in the database if needed. Pass it any
arguments given, keyword or positional.
Useful chiefly when chaining.
""" | python | {
"resource": ""
} |
q249493 | AbstractCharacter.copy_from | train | def copy_from(self, g):
"""Copy all nodes and edges from the given graph into this.
Return myself.
"""
renamed = {}
for k, v in g.node.items():
ok = k
if k in self.place:
n = 0
while k in self.place:
k ... | python | {
"resource": ""
} |
q249494 | AbstractCharacter.grid_2d_8graph | train | def grid_2d_8graph(self, m, n):
"""Make a 2d graph that's connected 8 ways, enabling diagonal movement"""
me = nx.Graph()
node = me.node
add_node = me.add_node
add_edge = me.add_edge
for i in range(m):
for j in range(n):
add_node((i, j))
... | python | {
"resource": ""
} |
q249495 | CharacterSense.func | train | def func(self):
"""Return the function most recently associated with this sense."""
fn = self.engine.query.sense_func_get(
self.observer.name,
self.sensename,
| python | {
"resource": ""
} |
q249496 | Character.place2thing | train | def place2thing(self, name, location):
"""Turn a Place into a Thing with the given location.
It will keep all its attached Portals.
"""
self.engine._set_thing_loc(
self.name, name, location
)
| python | {
"resource": ""
} |
q249497 | Character.thing2place | train | def thing2place(self, name):
"""Unset a Thing's location, and thus turn it into a Place."""
self.engine._set_thing_loc(
self.name, name, None
)
if (self.name, name) in self.engine._node_objs:
thing = self.engine._node_objs[self.name, name]
place = Plac... | python | {
"resource": ""
} |
q249498 | Character.del_avatar | train | def del_avatar(self, a, b=None):
"""This is no longer my avatar, though it still exists on its own."""
if self.engine._planning:
raise NotImplementedError("Currently can't remove avatars within a plan")
if b is None:
if not isinstance(a, Node):
raise TypeE... | python | {
"resource": ""
} |
q249499 | Character.portals | train | def portals(self):
"""Iterate over all portals."""
char = self.character
make_edge = self.engine._get_edge
for (o, d) in self.engine._edges_cache.iter_keys(
| python | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.