Skip to content

Commit e15654b

Browse files
ilevkivskyimsullivan
authored andcommitted
Always patch indirect dependencies (#5132)
1 parent b542af0 commit e15654b

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

mypy/build.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2057,9 +2057,9 @@ def finish_passes(self) -> None:
20572057
manager.options.dump_deps):
20582058
manager.all_types.update(self.type_map())
20592059

2060-
if self.options.incremental:
2061-
self._patch_indirect_dependencies(self.type_checker().module_refs,
2062-
self.type_map())
2060+
# We should always patch indirect dependencies, even in full (non-incremental) builds,
2061+
# because the cache still may be written, and it must be correct.
2062+
self._patch_indirect_dependencies(self.type_checker().module_refs, self.type_map())
20632063

20642064
if self.options.dump_inference_stats:
20652065
dump_type_stats(self.tree, self.xpath, inferred=True,

mypy/test/testcheck.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ def run_case_once(self, testcase: DataDrivenTestCase,
139139
options.show_traceback = True
140140
if 'optional' in testcase.file:
141141
options.strict_optional = True
142-
if incremental_step:
142+
if incremental_step and options.incremental:
143+
# Don't overwrite # flags: --no-incremental in incremental test cases
143144
options.incremental = True
144145
else:
145146
options.incremental = False

test-data/unit/check-incremental.test

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4410,3 +4410,21 @@ tmp/b.py:4: note: Expected:
44104410
tmp/b.py:4: note: def __iter__(self) -> Iterator[int]
44114411
tmp/b.py:4: note: Got:
44124412
tmp/b.py:4: note: def __iter__(self) -> Iterator[str]
4413+
4414+
[case testIndirectDepsAlwaysPatched-writescache]
4415+
# flags: --no-incremental
4416+
# flags2: --incremental
4417+
from b import C
4418+
def f() -> None:
4419+
x: int = C().x
4420+
[file b.py]
4421+
from c import C
4422+
[file c.pyi]
4423+
class C:
4424+
x: int
4425+
[file c.pyi.2]
4426+
class C:
4427+
x: str
4428+
[out]
4429+
[out2]
4430+
main:5: error: Incompatible types in assignment (expression has type "str", variable has type "int")

0 commit comments

Comments
 (0)