Skip to content

Commit 525e54a

Browse files
authored
Don't read errors from cache on silent import (#20508) (#20509)
When using `--follow-imports=silent`, we do not care about the errors in imported files, only about errors in the files we're explicitly reading. Fixes #20508.
1 parent 704aee6 commit 525e54a

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

mypy/build.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2180,7 +2180,8 @@ def __init__(
21802180
self.dep_hashes = {
21812181
k: v for (k, v) in zip(self.meta.dependencies, self.meta.dep_hashes)
21822182
}
2183-
self.error_lines = self.meta.error_lines
2183+
# Only copy `error_lines` if the module is not silently imported.
2184+
self.error_lines = [] if self.ignore_all else self.meta.error_lines
21842185
if temporary:
21852186
self.load_tree(temporary=True)
21862187
if not manager.use_fine_grained_cache():

test-data/unit/check-incremental.test

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2465,6 +2465,25 @@ def foo(a: int, b: int) -> str:
24652465
[out2]
24662466
tmp/b.py:2: error: Incompatible return value type (got "int", expected "str")
24672467

2468+
[case testIncrementalWithSilentImportsReverse]
2469+
-- Same commands as previous test, just in reverse order.
2470+
-- expected output is also in reverse order
2471+
# cmd: mypy -m b
2472+
# cmd2: mypy -m a
2473+
# flags: --follow-imports=silent
2474+
[file a.py]
2475+
import b
2476+
2477+
b.foo(1, 2)
2478+
2479+
[file b.py]
2480+
def foo(a: int, b: int) -> str:
2481+
return a + b
2482+
2483+
[out]
2484+
tmp/b.py:2: error: Incompatible return value type (got "int", expected "str")
2485+
[out2]
2486+
24682487
[case testForwardNamedTupleToUnionWithOtherNamedTUple]
24692488
from typing import NamedTuple, Union
24702489

0 commit comments

Comments
 (0)