Skip to content

Commit 8d621ad

Browse files
authored
Support --shadow-file with --native-parser (#21623)
1 parent 74ecdd8 commit 8d621ad

3 files changed

Lines changed: 97 additions & 1 deletion

File tree

mypy/build.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,9 @@ def parse_all(self, states: list[State], post_parse: bool = True) -> None:
10301030

10311031
parallel_states = []
10321032
for state in states:
1033-
if not self.fscache.exists(state.xpath, real_only=True):
1033+
if not self.fscache.exists(state.xpath, real_only=True) or (
1034+
self.shadow_map and self.maybe_swap_for_shadow_path(state.xpath) != state.xpath
1035+
):
10341036
state.source = state.get_source()
10351037
if state.tree is not None:
10361038
# The file was already parsed.

test-data/unit/check-incremental.test

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8139,3 +8139,68 @@ reveal_type(test("int"))
81398139
[out]
81408140
[out2]
81418141
tmp/b.py:2: note: Revealed type is "builtins.int"
8142+
8143+
[case testIncrementalNativeParserShadowFile]
8144+
# flags: --native-parser --shadow-file tmp/a.py tmp/a_shadow.py
8145+
import a
8146+
import b
8147+
-- a and b don't depend on each other, so they can be checked in parallel.
8148+
[file a.py]
8149+
x: int = 1
8150+
reveal_type(x)
8151+
[file b.py]
8152+
y: int = 2
8153+
[file a_shadow.py]
8154+
x: str = "y"
8155+
reveal_type(x)
8156+
[rechecked]
8157+
[stale]
8158+
[out1]
8159+
tmp/a.py:2: note: Revealed type is "builtins.str"
8160+
[out2]
8161+
tmp/a.py:2: note: Revealed type is "builtins.str"
8162+
8163+
[case testIncrementalNativeParserShadowFileChanged]
8164+
# flags: --native-parser --shadow-file tmp/a.py tmp/a_shadow.py
8165+
import a
8166+
import b
8167+
-- a and b don't depend on each other, so they can be checked in parallel.
8168+
[file a.py]
8169+
x: int = 1
8170+
reveal_type(x)
8171+
[file b.py]
8172+
y: int = 2
8173+
[file a_shadow.py]
8174+
x: str = "y"
8175+
reveal_type(x)
8176+
[file a_shadow.py.2]
8177+
x: bytes = b"y"
8178+
reveal_type(x)
8179+
[rechecked a]
8180+
[stale a]
8181+
[out1]
8182+
tmp/a.py:2: note: Revealed type is "builtins.str"
8183+
[out2]
8184+
tmp/a.py:2: note: Revealed type is "builtins.bytes"
8185+
8186+
[case testIncrementalNativeParserShadowFileIntroduced]
8187+
# flags: --native-parser
8188+
# flags2: --native-parser --shadow-file tmp/a.py tmp/a_shadow.py
8189+
import a
8190+
import b
8191+
-- a and b don't depend on each other, so they can be checked in parallel.
8192+
-- The first run has no shadow file; the second run introduces one for a.py.
8193+
[file a.py]
8194+
x: int = 1
8195+
reveal_type(x)
8196+
[file b.py]
8197+
y: int = 2
8198+
[file a_shadow.py.2]
8199+
x: str = "y"
8200+
reveal_type(x)
8201+
[rechecked a]
8202+
[stale a]
8203+
[out1]
8204+
tmp/a.py:2: note: Revealed type is "builtins.int"
8205+
[out2]
8206+
tmp/a.py:2: note: Revealed type is "builtins.str"

test-data/unit/cmdline.test

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,35 @@ variable has type "bytes")
530530
b: bytes = 1
531531
^
532532

533+
[case testShadowFileWithNativeParser]
534+
# cmd: mypy --native-parser --shadow-file source.py shadow.py source.py
535+
[file source.py]
536+
x: int = 1
537+
reveal_type(x)
538+
[file shadow.py]
539+
x: str = "y"
540+
reveal_type(x)
541+
[out]
542+
source.py:2: note: Revealed type is "str"
543+
== Return code: 0
544+
545+
[case testShadowFileWithNativeParserParallel]
546+
# cmd: mypy --native-parser --num-workers=4 --shadow-file a.py a_shadow.py main.py a.py b.py
547+
[file main.py]
548+
import a
549+
import b
550+
[file a.py]
551+
x: int = 1
552+
reveal_type(x)
553+
[file b.py]
554+
y: int = 2
555+
[file a_shadow.py]
556+
x: str = "y"
557+
reveal_type(x)
558+
[out]
559+
a.py:2: note: Revealed type is "str"
560+
== Return code: 0
561+
533562
[case testConfigWarnUnusedSection1]
534563
# cmd: mypy foo.py quux.py spam/eggs.py
535564
[file mypy.ini]

0 commit comments

Comments
 (0)