Skip to content

Commit

Permalink
Don't infinite loop on self deps in --follow-imports=normal (python#9302
Browse files Browse the repository at this point in the history
)

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.
  • Loading branch information
msullivan authored Aug 14, 2020
1 parent fbc45aa commit c2c72da
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions mypy/dmypy_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,10 @@ def fine_grained_increment_follow_imports(self, sources: List[BuildSource]) -> L
if module[0] not in graph:
continue
sources2 = self.direct_imports(module, graph)
# Filter anything already seen before. This prevents
# infinite looping if there are any self edges. (Self
# edges are maybe a bug, but...)
sources2 = [source for source in sources2 if source.module not in seen]
changed, new_files = self.find_reachable_changed_modules(
sources2, graph, seen, changed_paths
)
Expand Down

0 comments on commit c2c72da

Please sign in to comment.