MCPcopy Index your code
hub / github.com/python/cpython / add

Method add

Lib/graphlib.py:59–84  ·  view source on GitHub ↗

Add a new node and its predecessors to the graph. Both the *node* and all elements in *predecessors* must be hashable. If called multiple times with the same node argument, the set of dependencies will be the union of all dependencies passed in. It is possible to a

(self, node, *predecessors)

Source from the content-addressed store, hash-verified

57 return result
58
59 def add(self, node, *predecessors):
60 """Add a new node and its predecessors to the graph.
61
62 Both the *node* and all elements in *predecessors* must be hashable.
63
64 If called multiple times with the same node argument, the set of dependencies
65 will be the union of all dependencies passed in.
66
67 It is possible to add a node with no dependencies (*predecessors* is not provided)
68 as well as provide a dependency twice. If a node that has not been provided before
69 is included among *predecessors* it will be automatically added to the graph with
70 no predecessors of its own.
71
72 Raises ValueError if called after "prepare".
73 """
74 if self._ready_nodes is not None:
75 raise ValueError("Nodes cannot be added after a call to prepare()")
76
77 # Create the node -> predecessor edges
78 nodeinfo = self._get_nodeinfo(node)
79 nodeinfo.npredecessors += len(predecessors)
80
81 # Create the predecessor -> node edges
82 for pred in predecessors:
83 pred_info = self._get_nodeinfo(pred)
84 pred_info.successors.append(node)
85
86 def prepare(self):
87 """Mark the graph as finished and check for cycles in the graph.

Calls 2

_get_nodeinfoMethod · 0.95
appendMethod · 0.45