Skip to content

Commit

Permalink
Don't remove modules with descendants
Browse files Browse the repository at this point in the history
Modules are removed from the fine-grained build if they have not been
"seen".

This change ensures that we don't remove ancestor modules if their
descendants have been seen.
  • Loading branch information
meshy committed Jan 2, 2024
1 parent 81ea9fe commit 032999e
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion mypy/dmypy_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,10 +684,11 @@ def refresh_file(module: str, path: str) -> list[str]:

# Find all original modules in graph that were not reached -- they are deleted.
to_delete = []
seen_and_ancestors = self._seen_and_ancestors(seen)
for module_id in orig_modules:
if module_id not in graph:
continue
if module_id not in seen:
if module_id not in seen_and_ancestors:
module_path = graph[module_id].path
assert module_path is not None
to_delete.append((module_id, module_path))
Expand Down Expand Up @@ -715,6 +716,29 @@ def refresh_file(module: str, path: str) -> list[str]:

return messages

def _seen_and_ancestors(self, seen: set[str]) -> set[str]:
"""Return the set of seen modules along with any ancestors not already in the set.
For example, given this set:
{"foo", "foo.bar", "a.b.c"}
... we would expect this set to be returned:
{"foo", "foo.bar", "a.b.c", "a.b", "a"}
This is used to stop us from deleting ancestor modules from the graph
when their descendants have been seen.
"""
seen_paths = seen.copy()
for module_path in seen:
while module_path := module_path.rpartition(".")[0]:
if module_path in seen_paths:
break
else:
seen_paths.add(module_path)
return seen_paths

def find_reachable_changed_modules(
self,
roots: list[BuildSource],
Expand Down

0 comments on commit 032999e

Please sign in to comment.