Skip to content

Commit 321eb8f

Browse files
authored
Fix some fine-grained incremental bugs with newly imported files (#4502)
1 parent 8ec7046 commit 321eb8f

File tree

2 files changed

+55
-7
lines changed

2 files changed

+55
-7
lines changed

mypy/server/update.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def update(self, changed_modules: List[Tuple[str, str]]) -> List[str]:
225225
messages, remaining, (next_id, next_path), blocker = result
226226
changed_modules = [(id, path) for id, path in changed_modules
227227
if id != next_id]
228-
changed_modules = dedupe_modules(changed_modules + remaining)
228+
changed_modules = dedupe_modules(remaining + changed_modules)
229229
if blocker:
230230
self.blocking_error = (next_id, next_path)
231231
self.stale = changed_modules
@@ -283,8 +283,7 @@ def update_single(self, module: str, path: str) -> Tuple[List[str],
283283
update_dependencies({module: tree}, self.deps, graph, self.options)
284284
propagate_changes_using_dependencies(manager, graph, self.deps, triggered,
285285
{module},
286-
self.previous_targets_with_errors,
287-
graph)
286+
self.previous_targets_with_errors)
288287

289288
# Preserve state needed for the next update.
290289
self.previous_targets_with_errors = manager.errors.targets()
@@ -408,7 +407,10 @@ def update_single_isolated(module: str,
408407
remaining_modules = changed_modules
409408
# The remaining modules haven't been processed yet so drop them.
410409
for id, _ in remaining_modules:
411-
del manager.modules[id]
410+
if id in old_modules:
411+
manager.modules[id] = old_modules[id]
412+
else:
413+
del manager.modules[id]
412414
del graph[id]
413415
if DEBUG:
414416
print('--> %r (newly imported)' % module)
@@ -715,8 +717,7 @@ def propagate_changes_using_dependencies(
715717
deps: Dict[str, Set[str]],
716718
triggered: Set[str],
717719
up_to_date_modules: Set[str],
718-
targets_with_errors: Set[str],
719-
modules: Iterable[str]) -> None:
720+
targets_with_errors: Set[str]) -> None:
720721
# TODO: Multiple type checking passes
721722
num_iter = 0
722723

@@ -731,7 +732,7 @@ def propagate_changes_using_dependencies(
731732
# Also process targets that used to have errors, as otherwise some
732733
# errors might be lost.
733734
for target in targets_with_errors:
734-
id = module_prefix(modules, target)
735+
id = module_prefix(manager.modules, target)
735736
if id is not None and id not in up_to_date_modules:
736737
if id not in todo:
737738
todo[id] = set()

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,3 +746,50 @@ x = 1
746746
[delete a/b.py.2]
747747
[out]
748748
==
749+
750+
[case testAddImport]
751+
import what.b
752+
[file aaa/__init__.py]
753+
[file aaa/z.py]
754+
def foo(x: int) -> None:
755+
pass
756+
[file aaa/z.py.2]
757+
import config
758+
def foo() -> None:
759+
pass
760+
[file what/__init__.py]
761+
[file what/b.py]
762+
import config
763+
import aaa.z
764+
def main() -> None:
765+
aaa.z.foo(5)
766+
[file what/b.py.2]
767+
import aaa.z
768+
def main() -> None:
769+
aaa.z.foo()
770+
[file config.py]
771+
[out]
772+
==
773+
774+
[case testAddImport2]
775+
import what.b
776+
[file aaa/__init__.py]
777+
[file aaa/z.py]
778+
def foo(x: int) -> None:
779+
pass
780+
[file aaa/z.py.2]
781+
def foo() -> None:
782+
pass
783+
[file what/__init__.py]
784+
[file what/b.py]
785+
import aaa.z
786+
def main() -> None:
787+
aaa.z.foo(5)
788+
[file what/b.py.2]
789+
import config
790+
import aaa.z
791+
def main() -> None:
792+
aaa.z.foo()
793+
[file config.py]
794+
[out]
795+
==

0 commit comments

Comments
 (0)