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

Method prepare

Lib/graphlib.py:86–110  ·  view source on GitHub ↗

Mark the graph as finished and check for cycles in the graph. If any cycle is detected, "CycleError" will be raised, but "get_ready" can still be used to obtain as many nodes as possible until cycles block more progress. After a call to this function, the graph cannot be mod

(self)

Source from the content-addressed store, hash-verified

84 pred_info.successors.append(node)
85
86 def prepare(self):
87 """Mark the graph as finished and check for cycles in the graph.
88
89 If any cycle is detected, "CycleError" will be raised, but "get_ready" can
90 still be used to obtain as many nodes as possible until cycles block more
91 progress. After a call to this function, the graph cannot be modified and
92 therefore no more nodes can be added using "add".
93
94 Raise ValueError if nodes have already been passed out of the sorter.
95
96 """
97 if self._npassedout > 0:
98 raise ValueError("cannot prepare() after starting sort")
99
100 if self._ready_nodes is None:
101 self._ready_nodes = [
102 i.node for i in self._node2info.values() if i.npredecessors == 0
103 ]
104 # ready_nodes is set before we look for cycles on purpose:
105 # if the user wants to catch the CycleError, that's fine,
106 # they can continue using the instance to grab as many
107 # nodes as possible before cycles block more progress
108 cycle = self._find_cycle()
109 if cycle:
110 raise CycleError("nodes are in a cycle", cycle)
111
112 def get_ready(self):
113 """Return a tuple of all the nodes that are ready.

Callers 8

static_orderMethod · 0.95
_assert_cycleMethod · 0.95
test_doneMethod · 0.95
test_is_activeMethod · 0.95

Calls 3

_find_cycleMethod · 0.95
CycleErrorClass · 0.85
valuesMethod · 0.45

Tested by 7

_assert_cycleMethod · 0.76
test_doneMethod · 0.76
test_is_activeMethod · 0.76