Skip to content

Commit de58acc

Browse files
maintain node attr
1 parent bf70743 commit de58acc

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

pytools/graph.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,12 @@ class CycleError(Exception):
212212
"""
213213
Raised when a topological ordering cannot be computed due to a cycle.
214214
215+
:attr node: Node in a directed graph that is part of a cycle.
216+
215217
:attr nodes: List of nodes in a directed graph that are part of a cycle.
216218
"""
217-
def __init__(self, nodes: List[T]) -> None:
219+
def __init__(self, node: T, nodes: List[T]) -> None:
220+
self.node = node
218221
self.nodes = nodes
219222

220223

@@ -299,8 +302,11 @@ def compute_topological_order(graph: Mapping[T, Collection[T]],
299302

300303
if len(order) != total_num_nodes:
301304
# any node which has a predecessor left is a part of a cycle
302-
raise CycleError(list(n for n, num_preds in
305+
node = next(iter(n for n, num_preds in
303306
nodes_to_num_predecessors.items() if num_preds != 0))
307+
nodes = list(n for n, num_preds in
308+
nodes_to_num_predecessors.items() if num_preds != 0)
309+
raise CycleError(node, nodes)
304310

305311
return order
306312

0 commit comments

Comments
 (0)