Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,9 @@ def parse_all(self, states: list[State], post_parse: bool = True) -> None:

parallel_states = []
for state in states:
if not self.fscache.exists(state.xpath, real_only=True):
if not self.fscache.exists(state.xpath, real_only=True) or (
self.shadow_map and self.maybe_swap_for_shadow_path(state.xpath) != state.xpath
):
state.source = state.get_source()
if state.tree is not None:
# The file was already parsed.
Expand Down
97 changes: 97 additions & 0 deletions test-data/unit/check-incremental.test
Original file line number Diff line number Diff line change
Expand Up @@ -8139,3 +8139,100 @@ reveal_type(test("int"))
[out]
[out2]
tmp/b.py:2: note: Revealed type is "builtins.int"

[case testIncrementalNativeParserShadowFile]
# flags: --native-parser --shadow-file tmp/a.py tmp/a_shadow.py
import a
import b
[file a.py]
import c
x: int = 1
reveal_type(x)
[file b.py]
y: int = 2
[file c.py]
z: int = 3
[file a_shadow.py]
import c
x: str = "y"
reveal_type(x)
[rechecked]
[stale]
[out1]
tmp/a.py:3: note: Revealed type is "builtins.str"
[out2]
tmp/a.py:3: note: Revealed type is "builtins.str"

[case testIncrementalNativeParserShadowFileParallel]
# flags: --native-parser --num-workers=2 --shadow-file tmp/a.py tmp/a_shadow.py
import a
import b
-- a and b don't depend on each other, so they can be checked in parallel.
[file a.py]
x: int = 1
reveal_type(x)
[file b.py]
y: int = 2
reveal_type(y)
[file a_shadow.py]
x: str = "y"
reveal_type(x)
[rechecked]
[stale]
[out1]
tmp/a.py:2: note: Revealed type is "builtins.str"
tmp/b.py:2: note: Revealed type is "builtins.int"
[out2]
tmp/a.py:2: note: Revealed type is "builtins.str"
tmp/b.py:2: note: Revealed type is "builtins.int"

[case testIncrementalNativeParserShadowFileChanged]
# flags: --native-parser --num-workers=2 --shadow-file tmp/a.py tmp/a_shadow.py
import a
import b
-- a and b don't depend on each other, so they can be checked in parallel.
[file a.py]
x: int = 1
reveal_type(x)
[file b.py]
y: int = 2
reveal_type(y)
[file a_shadow.py]
x: str = "y"
reveal_type(x)
[file a_shadow.py.2]
x: bytes = b"y"
reveal_type(x)
[rechecked a]
[stale a]
[out1]
tmp/a.py:2: note: Revealed type is "builtins.str"
tmp/b.py:2: note: Revealed type is "builtins.int"
[out2]
tmp/a.py:2: note: Revealed type is "builtins.bytes"
tmp/b.py:2: note: Revealed type is "builtins.int"

[case testIncrementalNativeParserShadowFileIntroduced]
# flags: --native-parser --num-workers=2

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, btw, all testcheck.py tests are run in parallel mode in the parallel CI jobs. So I am not sure we need to keep both here. (The cmdline.test however is not run by testcheck.py, so keeping a separate parallel test there makes sense.)

# flags2: --native-parser --num-workers=2 --shadow-file tmp/a.py tmp/a_shadow.py
import a
import b
-- a and b don't depend on each other, so they can be checked in parallel.
-- The first run has no shadow file; the second run introduces one for a.py.
[file a.py]
x: int = 1
reveal_type(x)
[file b.py]
y: int = 2
reveal_type(y)
[file a_shadow.py.2]
x: str = "y"
reveal_type(x)
[rechecked a]
[stale a]
[out1]
tmp/a.py:2: note: Revealed type is "builtins.int"
tmp/b.py:2: note: Revealed type is "builtins.int"
[out2]
tmp/a.py:2: note: Revealed type is "builtins.str"
tmp/b.py:2: note: Revealed type is "builtins.int"
29 changes: 29 additions & 0 deletions test-data/unit/cmdline.test
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,35 @@ variable has type "bytes")
b: bytes = 1
^

[case testShadowFileWithNativeParser]
# cmd: mypy --native-parser --shadow-file source.py shadow.py source.py
[file source.py]
x: int = 1
reveal_type(x)
[file shadow.py]
x: str = "y"
reveal_type(x)
[out]
source.py:2: note: Revealed type is "str"
== Return code: 0

[case testShadowFileWithNativeParserParallel]
# cmd: mypy --native-parser --num-workers=4 --shadow-file a.py a_shadow.py main.py a.py b.py
[file main.py]
import a
import b
[file a.py]
x: int = 1
reveal_type(x)
[file b.py]
y: int = 2
[file a_shadow.py]
x: str = "y"
reveal_type(x)
[out]
a.py:2: note: Revealed type is "str"
== Return code: 0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is worth adding an incremental test for --shadow-file in parallel mode as well.


[case testConfigWarnUnusedSection1]
# cmd: mypy foo.py quux.py spam/eggs.py
[file mypy.ini]
Expand Down
Loading