Skip to content

Commit

Permalink
Fix from p import q when p/q.py removed from fine-grained build (#4988
Browse files Browse the repository at this point in the history
)
  • Loading branch information
msullivan committed May 1, 2018
1 parent 8248a68 commit c0f2f95
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
7 changes: 6 additions & 1 deletion mypy/server/update.py
Expand Up @@ -461,7 +461,7 @@ def update_module_isolated(module: str,
manager.log_fine_grained('new module %r' % module)

if not manager.fscache.isfile(path) or force_removed:
delete_module(module, graph, manager)
delete_module(module, path, graph, manager)
return NormalUpdate(module, path, [], None)

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


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


def dedupe_modules(modules: List[Tuple[str, str]]) -> List[Tuple[str, str]]:
Expand Down
19 changes: 19 additions & 0 deletions test-data/unit/fine-grained-modules.test
Expand Up @@ -134,6 +134,25 @@ b.py:1: error: Name 'f' is not defined
==
b.py:1: error: Name 'f' is not defined

[case testRemoveSubmoduleFromBuild1]
# cmd1: mypy a.py b/__init__.py b/c.py
# cmd2: mypy a.py b/__init__.py
# flags: --follow-imports=skip --ignore-missing-imports
[file a.py]
from b import c
x=1
[file a.py.2]
from b import c
x=2
[file a.py.3]
from b import c
x=3
[file b/__init__.py]
[file b/c.py]
[out]
==
==

[case testImportLineNumber1]
import b
[file b.py]
Expand Down

0 comments on commit c0f2f95

Please sign in to comment.