Detecting Cycles and Loops in a Dependency Graph
A cycle in a build graph, an import graph or a task DAG turns a topological sort into an error message that usually does not say which edges are at fault. Getting the path out is not much harder than getting the boolean, and it is the only version anyone can act on. The first attempt almost everyone writes keeps a single visited set and reports a cycle when it reaches a node already in it: # WRONG def has_cycle(graph): visited = set() def dfs(node): if node in visited:
