Skip to content

Commit 87f7d90

Browse files
Michael0x2agvanrossum
authored andcommitted
Fix overzealous new submodule check (#2189)
Fixes #2028. Previously, when mypy detected a module acquired a new submodule after running mypy once in incremental, mypy would attempt to parse the module from scratch (if it hadn't already previously been parsed) which, as a side-effect, would find all of the child modules and load them as dependencies of the top-level module. While this works in the usual case, this check made the flawed assumption that we would want to actually record every single new submodule that was created. This assumption is not necessarily true when using --silent-imports -- it may be the case that we only want to record a _subset_ of the new submodules that were created, depending on what exactly the command line flags were.
1 parent c3e1b35 commit 87f7d90

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

mypy/build.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,6 +1536,7 @@ def load_graph(sources: List[BuildSource], manager: BuildManager) -> Graph:
15361536
for id, g in graph.items():
15371537
if g.has_new_submodules():
15381538
g.parse_file()
1539+
g.fix_suppressed_dependencies(graph)
15391540
g.mark_interface_stale()
15401541
return graph
15411542

test-data/unit/check-incremental.test

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,3 +1567,26 @@ class Outer:
15671567
[out2]
15681568
main:1: note: In module imported here:
15691569
tmp/foo.py:3: error: Argument 1 to "accept_int" has incompatible type "str"; expected "int"
1570+
1571+
[case testIncrementalPartialSubmoduleUpdate]
1572+
# cmd: mypy -m a
1573+
# cmd2: mypy -m a a.c
1574+
# flags: --silent-imports
1575+
1576+
[file a/__init__.py]
1577+
from .b import B
1578+
from .c import C
1579+
1580+
[file a/b.py]
1581+
class B: pass
1582+
1583+
[file a/c.py]
1584+
class C: pass
1585+
1586+
[file a/c.py.next]
1587+
class C: pass
1588+
pass
1589+
1590+
[rechecked a, a.c]
1591+
[stale a, a.c]
1592+
[out]

0 commit comments

Comments
 (0)