Whole file

mgedmin/findimports

The author described this change as Fix incorrect transitive closure computation when cycles exist. It counts as a record because the check below fails on the code as it stood at fa9f9f5bb and passes on efab46e80, with nothing else changed between the two runs.

Fix saved2025-12-08
Sharing licenceMIT · LICENSE
Change size+11 9

What the code was meant to do, written into the code itself as a save note

Fix incorrect transitive closure computation when cycles exist

The change

977977
978978 def transitiveClosure(self):
979979 """Compute a transitive closure of the graph."""
980- mods_reachable_from = {}
980+ reachable = set()
981981
982982 def visit(modname):
983- reachable = mods_reachable_from.get(modname)
984- if reachable is None:
985- reachable = mods_reachable_from[modname] = {modname}
986- module = self.modules.get(modname)
987- if module:
988- for impname in module.imports:
989- reachable.update(visit(impname))
990- return reachable
983+ reachable.add(modname)
984+ module = self.modules.get(modname)
985+ if module:
986+ for impname in module.imports:
987+ if impname not in reachable:
988+ reachable.add(impname)
989+ visit(impname)
991990
991+ mods_reachable_from = {}
992992 for modname in self.modules:
993993 visit(modname)
994+ mods_reachable_from[modname] = reachable
995+ reachable = set()
994996
995997 return mods_reachable_from
996998

The check that tells the two apart

failpass·tests.py::test_transitive_closure_handles_loops

Check file tests.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before itfa9f9f5bb20a746d5c9a846dc891491345d3d850
Broken version dated2025-12-08
Modulefindimports
Units changedModuleGraph
Fingerprintbe32c6e6e82d4dd8
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.