Skip to content

Commit f38b284

Browse files
committed
Fix fine-grained crash caused by unneeded extra parse_file()s (#4980)
load_graph() contains code to parse ancestor modules that get new children. Since load_graph() did not communicate that these modules had been parsed to fine-grained mode, this caused problems with fine-grained mode. That code was added in #1865 to fix a bug where 'import from' of a newly added submodule would not work in incremental mode because it didn't appear in the parent module's symbol table. The need to reload the parent to fix this was obviated by at the modules map to find possible submodules. Since the code isn't needed any more and it is causing trouble, we just remove it.
1 parent 7f13e6e commit f38b284

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

mypy/build.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,10 +1681,6 @@ def is_fresh(self) -> bool:
16811681
def is_interface_fresh(self) -> bool:
16821682
return self.externally_same
16831683

1684-
def has_new_submodules(self) -> bool:
1685-
"""Return if this module has new submodules after being loaded from a warm cache."""
1686-
return self.meta is not None and self.child_modules != set(self.meta.child_modules)
1687-
16881684
def mark_as_rechecked(self) -> None:
16891685
"""Marks this module as having been fully re-analyzed by the type-checker."""
16901686
self.manager.rechecked_modules.add(self.id)
@@ -2417,11 +2413,6 @@ def load_graph(sources: List[BuildSource], manager: BuildManager,
24172413
if dep in st.suppressed:
24182414
st.suppressed.remove(dep)
24192415
st.dependencies.append(dep)
2420-
for id, g in graph.items():
2421-
if g.has_new_submodules():
2422-
g.parse_file()
2423-
g.fix_suppressed_dependencies(graph)
2424-
g.mark_interface_stale()
24252416
return graph
24262417

24272418

mypy/server/update.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,9 @@ def ensure_trees_loaded(manager: BuildManager, graph: Dict[str, State],
399399
"""Ensure that the modules in initial and their deps have loaded trees."""
400400
to_process = find_unloaded_deps(manager, graph, initial)
401401
if to_process:
402-
manager.log_fine_grained("Calling process_fresh_modules on set of size {} ({})".format(
403-
len(to_process), to_process))
402+
if is_verbose(manager):
403+
manager.log_fine_grained("Calling process_fresh_modules on set of size {} ({})".format(
404+
len(to_process), sorted(to_process)))
404405
process_fresh_modules(graph, to_process, manager)
405406

406407

test-data/unit/check-incremental.test

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,8 @@ from parent import b
946946

947947
[file parent/b.py.2]
948948

949-
[stale parent, parent.a, parent.b]
949+
[stale parent.a, parent.b]
950+
[rechecked parent, parent.a, parent.b]
950951

951952
[case testIncrementalReferenceExistingFileWithImportFrom]
952953
from parent import a, b

test-data/unit/fine-grained-modules.test

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,18 @@ main:1: error: Cannot find module named 'p.q'
436436
main:1: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" flag would help)
437437
==
438438

439+
[case testDeleteSubpackageWithNontrivialParent1]
440+
[file p/__init__.py]
441+
def g() -> None:
442+
pass
443+
[file p/b.py.2]
444+
def foo() -> None: pass
445+
foo()
446+
[delete p/b.py.3]
447+
[out]
448+
==
449+
==
450+
439451
[case testDeleteModuleWithError]
440452
import a
441453
[file a.py]

0 commit comments

Comments
 (0)