Skip to content

Commit c0f2f95

Browse files
authored
Fix from p import q when p/q.py removed from fine-grained build (#4988)
1 parent 8248a68 commit c0f2f95

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

mypy/server/update.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ def update_module_isolated(module: str,
461461
manager.log_fine_grained('new module %r' % module)
462462

463463
if not manager.fscache.isfile(path) or force_removed:
464-
delete_module(module, graph, manager)
464+
delete_module(module, path, graph, manager)
465465
return NormalUpdate(module, path, [], None)
466466

467467
sources = get_sources(manager.fscache, previous_modules, [(module, path)])
@@ -579,6 +579,7 @@ def find_relative_leaf_module(modules: List[Tuple[str, str]], graph: Graph) -> T
579579

580580

581581
def delete_module(module_id: str,
582+
path: str,
582583
graph: Graph,
583584
manager: BuildManager) -> None:
584585
manager.log_fine_grained('delete module %r' % module_id)
@@ -596,6 +597,10 @@ def delete_module(module_id: str,
596597
parent = manager.modules[parent_id]
597598
if components[-1] in parent.names:
598599
del parent.names[components[-1]]
600+
# If the module is removed from the build but still exists, then
601+
# we mark it as missing so that it will get picked up by import from still.
602+
if manager.fscache.isfile(path):
603+
manager.missing_modules.add(module_id)
599604

600605

601606
def dedupe_modules(modules: List[Tuple[str, str]]) -> List[Tuple[str, str]]:

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,25 @@ b.py:1: error: Name 'f' is not defined
134134
==
135135
b.py:1: error: Name 'f' is not defined
136136

137+
[case testRemoveSubmoduleFromBuild1]
138+
# cmd1: mypy a.py b/__init__.py b/c.py
139+
# cmd2: mypy a.py b/__init__.py
140+
# flags: --follow-imports=skip --ignore-missing-imports
141+
[file a.py]
142+
from b import c
143+
x=1
144+
[file a.py.2]
145+
from b import c
146+
x=2
147+
[file a.py.3]
148+
from b import c
149+
x=3
150+
[file b/__init__.py]
151+
[file b/c.py]
152+
[out]
153+
==
154+
==
155+
137156
[case testImportLineNumber1]
138157
import b
139158
[file b.py]

0 commit comments

Comments
 (0)