Skip to content

Commit c2c72da

Browse files
authored
Don't infinite loop on self deps in --follow-imports=normal (python#9302)
There are situations in complex SCCs where the semantic analyzer will infer self dependencies, which will cause an infinite loop in `dmypy --follow-imports=normal`. It's probably a bug that we do that, and that should be fixed to, but fixing a graph algorithm to not infinite loop on self edges seems like a reasonable thing to do in any case. I don't have a minimized test case yet, and am submitting this without one because it should be harmless and because I want it to get into the release.
1 parent fbc45aa commit c2c72da

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

mypy/dmypy_server.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,10 @@ def fine_grained_increment_follow_imports(self, sources: List[BuildSource]) -> L
557557
if module[0] not in graph:
558558
continue
559559
sources2 = self.direct_imports(module, graph)
560+
# Filter anything already seen before. This prevents
561+
# infinite looping if there are any self edges. (Self
562+
# edges are maybe a bug, but...)
563+
sources2 = [source for source in sources2 if source.module not in seen]
560564
changed, new_files = self.find_reachable_changed_modules(
561565
sources2, graph, seen, changed_paths
562566
)

0 commit comments

Comments
 (0)