Skip to content

Commit 1f68fc6

Browse files
committed
Don't remove modules with descendants
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.
1 parent 2cdc138 commit 1f68fc6

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

mypy/dmypy_server.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,10 +684,11 @@ def refresh_file(module: str, path: str) -> list[str]:
684684

685685
# Find all original modules in graph that were not reached -- they are deleted.
686686
to_delete = []
687+
seen_and_ancestors = self._seen_and_ancestors(seen)
687688
for module_id in orig_modules:
688689
if module_id not in graph:
689690
continue
690-
if module_id not in seen:
691+
if module_id not in seen_and_ancestors:
691692
module_path = graph[module_id].path
692693
assert module_path is not None
693694
to_delete.append((module_id, module_path))
@@ -715,6 +716,29 @@ def refresh_file(module: str, path: str) -> list[str]:
715716

716717
return messages
717718

719+
def _seen_and_ancestors(self, seen: set[str]) -> set[str]:
720+
"""Return the set of seen modules along with any ancestors not already in the set.
721+
722+
For example, given this set:
723+
724+
{"foo", "foo.bar", "a.b.c"}
725+
726+
... we would expect this set to be returned:
727+
728+
{"foo", "foo.bar", "a.b.c", "a.b", "a"}
729+
730+
This is used to stop us from deleting ancestor modules from the graph
731+
when their descendants have been seen.
732+
"""
733+
seen_paths = seen.copy()
734+
for module_path in seen:
735+
while module_path := module_path.rpartition(".")[0]:
736+
if module_path in seen_paths:
737+
break
738+
else:
739+
seen_paths.add(module_path)
740+
return seen_paths
741+
718742
def find_reachable_changed_modules(
719743
self,
720744
roots: list[BuildSource],

0 commit comments

Comments
 (0)