From 106867e03d4a2d1375a5ec5a17f19f848b1d4f2d Mon Sep 17 00:00:00 2001 From: Michael Sullivan Date: Tue, 23 Jan 2018 09:37:57 -0800 Subject: [PATCH 1/2] Fix some fine-grained incremental bugs with newly imported files --- mypy/server/update.py | 9 +++-- test-data/unit/fine-grained-modules.test | 47 ++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/mypy/server/update.py b/mypy/server/update.py index f5caa3bf561c..2029236b9268 100644 --- a/mypy/server/update.py +++ b/mypy/server/update.py @@ -225,7 +225,7 @@ def update(self, changed_modules: List[Tuple[str, str]]) -> List[str]: messages, remaining, (next_id, next_path), blocker = result changed_modules = [(id, path) for id, path in changed_modules if id != next_id] - changed_modules = dedupe_modules(changed_modules + remaining) + changed_modules = dedupe_modules(remaining + changed_modules) if blocker: self.blocking_error = (next_id, next_path) self.stale = changed_modules @@ -284,7 +284,7 @@ def update_single(self, module: str, path: str) -> Tuple[List[str], propagate_changes_using_dependencies(manager, graph, self.deps, triggered, {module}, self.previous_targets_with_errors, - graph) + self.manager.modules) # Preserve state needed for the next update. self.previous_targets_with_errors = manager.errors.targets() @@ -408,7 +408,10 @@ def update_single_isolated(module: str, remaining_modules = changed_modules # The remaining modules haven't been processed yet so drop them. for id, _ in remaining_modules: - del manager.modules[id] + if id in old_modules: + manager.modules[id] = old_modules[id] + else: + del manager.modules[id] del graph[id] if DEBUG: print('--> %r (newly imported)' % module) diff --git a/test-data/unit/fine-grained-modules.test b/test-data/unit/fine-grained-modules.test index ba23404131a1..91c7589e6362 100644 --- a/test-data/unit/fine-grained-modules.test +++ b/test-data/unit/fine-grained-modules.test @@ -746,3 +746,50 @@ x = 1 [delete a/b.py.2] [out] == + +[case testAddImport] +import what.b +[file aaa/__init__.py] +[file aaa/z.py] +def foo(x: int) -> None: + pass +[file aaa/z.py.2] +import config +def foo() -> None: + pass +[file what/__init__.py] +[file what/b.py] +import config +import aaa.z +def main() -> None: + aaa.z.foo(5) +[file what/b.py.2] +import aaa.z +def main() -> None: + aaa.z.foo() +[file config.py] +[out] +== + +[case testAddImport2] +import what.b +[file aaa/__init__.py] +[file aaa/z.py] +def foo(x: int) -> None: + pass +[file aaa/z.py.2] +def foo() -> None: + pass +[file what/__init__.py] +[file what/b.py] +import aaa.z +def main() -> None: + aaa.z.foo(5) +[file what/b.py.2] +import config +import aaa.z +def main() -> None: + aaa.z.foo() +[file config.py] +[out] +== From a3cc17503c0dc1a500074e9dc879869d6b8ea141 Mon Sep 17 00:00:00 2001 From: Michael Sullivan Date: Wed, 24 Jan 2018 16:18:01 -0800 Subject: [PATCH 2/2] Drop modules arg to propagate_changes_using_dependencies --- mypy/server/update.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/mypy/server/update.py b/mypy/server/update.py index 2029236b9268..e322b7bef315 100644 --- a/mypy/server/update.py +++ b/mypy/server/update.py @@ -283,8 +283,7 @@ def update_single(self, module: str, path: str) -> Tuple[List[str], update_dependencies({module: tree}, self.deps, graph, self.options) propagate_changes_using_dependencies(manager, graph, self.deps, triggered, {module}, - self.previous_targets_with_errors, - self.manager.modules) + self.previous_targets_with_errors) # Preserve state needed for the next update. self.previous_targets_with_errors = manager.errors.targets() @@ -718,8 +717,7 @@ def propagate_changes_using_dependencies( deps: Dict[str, Set[str]], triggered: Set[str], up_to_date_modules: Set[str], - targets_with_errors: Set[str], - modules: Iterable[str]) -> None: + targets_with_errors: Set[str]) -> None: # TODO: Multiple type checking passes num_iter = 0 @@ -734,7 +732,7 @@ def propagate_changes_using_dependencies( # Also process targets that used to have errors, as otherwise some # errors might be lost. for target in targets_with_errors: - id = module_prefix(modules, target) + id = module_prefix(manager.modules, target) if id is not None and id not in up_to_date_modules: if id not in todo: todo[id] = set()