Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
38 changes: 33 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,20 @@ jobs:
os: ubuntu-24.04-arm
toxenv: py
tox_extra_args: "-n 4 --mypy-num-workers=4 mypy/test/testcheck.py"
dev_ast_serialize: true
- name: Parallel tests with py314-ubuntu, mypyc-compiled
python: '3.14'
os: ubuntu-24.04-arm
toxenv: py
tox_extra_args: "-n 4 --mypy-num-workers=4 mypy/test/testcheck.py"
test_mypyc: true
- name: Parallel tests with py314-windows-64, interpreted
python: '3.14'
os: windows-latest
toxenv: py
tox_extra_args: "-n 2 --mypy-num-workers=2 mypy/test/testcheck.py -k 'incremental or modules or classes'"
dev_ast_serialize: true
# Skip Windows tests until we publish ast_serialize wheels on PyPI.
# - name: Parallel tests with py314-windows-64, interpreted
# python: '3.14'
# os: windows-latest
# toxenv: py
# tox_extra_args: "-n 2 --mypy-num-workers=2 mypy/test/testcheck.py -k 'incremental or modules or classes'"

- name: Type check our own code (py310-ubuntu)
python: '3.10'
Expand All @@ -139,6 +142,7 @@ jobs:
timeout-minutes: 60
env:
TOX_SKIP_MISSING_INTERPRETERS: False
VIRTUALENV_SYSTEM_SITE_PACKAGES: ${{ matrix.dev_ast_serialize && 1 || 0 }}
# Rich (pip) -- Disable color for windows + pytest
FORCE_COLOR: ${{ !(startsWith(matrix.os, 'windows-') && startsWith(matrix.toxenv, 'py')) && 1 || 0 }}
# Tox
Expand Down Expand Up @@ -213,6 +217,30 @@ jobs:
pip install -r test-requirements.txt
CC=clang MYPYC_OPT_LEVEL=0 MYPY_USE_MYPYC=1 pip install -e .

# To speed-up process until ast_serialize is on PyPI.
- name: Checkout pinned ast_serialize
if: ${{ matrix.dev_ast_serialize }}
uses: actions/checkout@v4
with:
persist-credentials: false
repository: mypyc/ast_serialize
ref: da5a16cf268dbec63ed6b2e6b715470576e2d1a6
path: ast_serialize

- if: ${{ matrix.dev_ast_serialize }}
uses: PyO3/maturin-action@v1
with:
target: aarch64
args: --release --out dist
working-directory: ast_serialize

- if: ${{ matrix.dev_ast_serialize }}
run: |
pip install ast_serialize/dist/ast_serialize-0.1.0-cp39-abi3-manylinux_2_34_aarch64.whl
echo 'no way' > test_ast_serialize.py
python3 -c 'import ast_serialize; print(ast_serialize.parse("test_ast_serialize.py")[1])'
rm test_ast_serialize.py

- name: Setup tox environment
run: |
tox run -e ${{ matrix.toxenv }} --notest
Expand Down
2 changes: 1 addition & 1 deletion mypy/message_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def with_additional_msg(self, info: str) -> ErrorMessage:
"Condition can't be inferred, unable to merge overloads"
)
TYPE_IGNORE_WITH_ERRCODE_ON_MODULE: Final = ErrorMessage(
"type ignore with error code is not supported for modules; "
"Type ignore with error code is not supported for modules; "
'use `# mypy: disable-error-code="{}"`',
codes.SYNTAX,
)
Expand Down
4 changes: 4 additions & 0 deletions mypy/test/testcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,16 @@ def run_case_once(

if options.num_workers:
options.fixed_format_cache = True
options.native_parser = True
if testcase.output_files:
raise pytest.skip("Reports are not supported in parallel mode")
# Note: do not use this unless really needed!
if testcase.name.endswith("_no_parallel"):
raise pytest.skip("Test not supported in parallel mode yet")

if options.native_parser and testcase.name.endswith("_no_native_parse"):
raise pytest.skip("Test not supported by native parser yet")

# Enable some options automatically based on test file name.
if "columns" in testcase.file:
options.show_column_numbers = True
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/check-annotated.test
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ x: Annotated[int, THESE, ARE, IGNORED, FOR, NOW]
reveal_type(x) # N: Revealed type is "builtins.int"
[builtins fixtures/tuple.pyi]

[case testAnnotated3]
[case testAnnotated3_no_native_parse]
from typing_extensions import Annotated
x: Annotated[int, -+~12.3, "som"[e], more(anno+a+ions, that=[are]), (b"ignored",), 4, N.O.W, ...]
reveal_type(x) # N: Revealed type is "builtins.int"
Expand Down
4 changes: 2 additions & 2 deletions test-data/unit/check-async-await.test
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ async def f() -> None:
[builtins fixtures/async_await.pyi]
[typing fixtures/typing-async.pyi]

[case testAsyncForTypeComments]
[case testAsyncForTypeComments_no_native_parse]

from typing import AsyncIterator, Union
class C(AsyncIterator[int]):
Expand Down Expand Up @@ -342,7 +342,7 @@ async def f() -> None:
[builtins fixtures/async_await.pyi]
[typing fixtures/typing-async.pyi]

[case testAsyncWithTypeComments]
[case testAsyncWithTypeComments_no_native_parse]

class C:
async def __aenter__(self) -> int: pass
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/check-basic.test
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ x = 1
x in 1, # E: Unsupported right operand type for in ("int")
[builtins fixtures/tuple.pyi]

[case testTrailingCommaInIfParsing]
[case testTrailingCommaInIfParsing_no_native_parse]
if x in 1, : pass
[out]
main:1: error: Invalid syntax
Expand Down
6 changes: 3 additions & 3 deletions test-data/unit/check-columns.test
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Test column numbers in messages. --show-column-numbers is enabled implicitly by test runner.

[case testColumnsSyntaxError]
[case testColumnsSyntaxError_no_native_parse]
f()
1 +
[out]
Expand Down Expand Up @@ -146,7 +146,7 @@ if int():
def f(a: 'A') -> None: pass
(f(b=object())) # E:6: Unexpected keyword argument "b" for "f"

[case testColumnInvalidType]
[case testColumnInvalidType_no_native_parse]

from typing import Iterable

Expand Down Expand Up @@ -342,7 +342,7 @@ if int():
main:2:11: error: Syntax error in type annotation
main:2:11: note: Suggestion: Is there a spurious trailing comma?

[case testColumnSyntaxErrorInTypeAnnotation2]
[case testColumnSyntaxErrorInTypeAnnotation2_no_native_parse]
if int():
# TODO: It would be better to point to the type comment
xyz = 0 # type: blurbnard blarb
Expand Down
20 changes: 10 additions & 10 deletions test-data/unit/check-errorcodes.test
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@ class A:
[case testErrorCodeNoteHasNoCode]
reveal_type(1) # N: Revealed type is "Literal[1]?"

[case testErrorCodeSyntaxError]
[case testErrorCodeSyntaxError_no_native_parse]
1 ''
[out]
main:1: error: Invalid syntax [syntax]
[out version==3.10.0]
main:1: error: Invalid syntax. Perhaps you forgot a comma? [syntax]

[case testErrorCodeSyntaxError2]
[case testErrorCodeSyntaxError2_no_native_parse]
def f(): # E: Type signature has too many parameters [syntax]
# type: (int) -> None
1

x = 0 # type: x y # E: Syntax error in type comment "x y" [syntax]

[case testErrorCodeSyntaxError3]
[case testErrorCodeSyntaxError3_no_native_parse]
# This is a bit inconsistent -- syntax error would be more logical?
x: 'a b' # E: Invalid type comment or annotation [valid-type]
for v in x: # type: int, int # E: Syntax error in type annotation [syntax] \
Expand Down Expand Up @@ -208,7 +208,7 @@ def h(x # type: xyz # type: ignore[foo] # E: Name "xyz" is not defined [name
import nostub # type: ignore[import]
from defusedxml import xyz # type: ignore[import]

[case testErrorCodeBadIgnore]
[case testErrorCodeBadIgnore_no_native_parse]
import nostub # type: ignore xyz # E: Invalid "type: ignore" comment [syntax] \
# E: Cannot find implementation or library stub for module named "nostub" [import-not-found] \
# N: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
Expand All @@ -226,7 +226,7 @@ def f(x, # type: int # type: ignore[ # E: Invalid "type: ignore" comment [sy
# type: (...) -> None
pass

[case testErrorCodeBadIgnoreNoExtraComment]
[case testErrorCodeBadIgnoreNoExtraComment_no_native_parse]
# Omit the E: ... comments, as they affect parsing
import nostub # type: ignore xyz
import nostub # type: ignore[xyz
Expand Down Expand Up @@ -762,7 +762,7 @@ main:1: error: Name "y" is not defined [name-defined]
main:2: error: Name "ignored" is not defined [name-defined]
main:2: error: Name "y" is not defined [name-defined]

[case testErrorCodeTypeIgnoreMisspelled2]
[case testErrorCodeTypeIgnoreMisspelled2_no_native_parse]
x = y # type: int # type: ignored[foo]
x = y # type: int # type: ignored [foo]
[out]
Expand Down Expand Up @@ -1014,7 +1014,7 @@ def f(arg: int) -> int:
def f(arg: str) -> str:
...

[case testSliceInDictBuiltin]
[case testSliceInDictBuiltin_no_native_parse]
# flags: --show-column-numbers
b: dict[int, x:y]
c: dict[x:y]
Expand All @@ -1027,7 +1027,7 @@ main:3:4: error: "dict" expects 2 type arguments, but 1 given [type-arg]
main:3:9: error: Invalid type comment or annotation [valid-type]
main:3:9: note: did you mean to use ',' instead of ':' ?

[case testSliceInDictTyping]
[case testSliceInDictTyping_no_native_parse]
# flags: --show-column-numbers
from typing import Dict
b: Dict[int, x:y]
Expand Down Expand Up @@ -1067,11 +1067,11 @@ def f(d: D, s: str) -> None:
[typing fixtures/typing-typeddict.pyi]

[case testRecommendErrorCode]
# type: ignore[whatever] # E: type ignore with error code is not supported for modules; use `# mypy: disable-error-code="whatever"` [syntax]
# type: ignore[whatever] # E: Type ignore with error code is not supported for modules; use `# mypy: disable-error-code="whatever"` [syntax]
1 + "asdf"

[case testRecommendErrorCode2]
# type: ignore[whatever, other] # E: type ignore with error code is not supported for modules; use `# mypy: disable-error-code="whatever, other"` [syntax]
# type: ignore[whatever, other] # E: Type ignore with error code is not supported for modules; use `# mypy: disable-error-code="whatever, other"` [syntax]
1 + "asdf"

[case testShowErrorCodesInConfig]
Expand Down
4 changes: 2 additions & 2 deletions test-data/unit/check-expressions.test
Original file line number Diff line number Diff line change
Expand Up @@ -1456,7 +1456,7 @@ if int():
b = (x for x in a) # E: Generator has incompatible item type "Callable[[], str]"; expected "Callable[[], int]"
[builtins fixtures/list.pyi]

[case testGeneratorNoSpuriousError]
[case testGeneratorNoSpuriousError_no_native_parse]
from typing import Iterable, overload

@overload
Expand Down Expand Up @@ -1915,7 +1915,7 @@ None == None
None < None # E: Unsupported left operand type for < ("None")
[builtins fixtures/ops.pyi]

[case testDictWithStarExpr]
[case testDictWithStarExpr_no_native_parse]

b = {'z': 26, *a} # E: Invalid syntax
[builtins fixtures/dict.pyi]
Expand Down
14 changes: 7 additions & 7 deletions test-data/unit/check-fastparse.test
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[case testFastParseSyntaxError]
[case testFastParseSyntaxError_no_native_parse]

1 + # E: Invalid syntax

[case testFastParseTypeCommentSyntaxError]
[case testFastParseTypeCommentSyntaxError_no_native_parse]

x = None # type: a : b # E: Syntax error in type comment "a : b"

Expand All @@ -12,13 +12,13 @@ x = None # type: a + b # E: Invalid type comment or annotation

-- Function type comments are attributed to the function def line.
-- This happens in both parsers.
[case testFastParseFunctionAnnotationSyntaxError]
[case testFastParseFunctionAnnotationSyntaxError_no_native_parse]

def f(): # E: Syntax error in type comment "None -> None" # N: Suggestion: wrap argument types in parentheses
# type: None -> None
pass

[case testFastParseFunctionAnnotationSyntaxErrorSpaces]
[case testFastParseFunctionAnnotationSyntaxErrorSpaces_no_native_parse]

def f(): # E: Syntax error in type comment "None -> None" # N: Suggestion: wrap argument types in parentheses
# type: None -> None
Expand Down Expand Up @@ -156,7 +156,7 @@ def f(a, # type: A
[builtins fixtures/dict.pyi]
[out]

[case testFastParsePerArgumentAnnotationsWithAnnotatedBareStar]
[case testFastParsePerArgumentAnnotationsWithAnnotatedBareStar_no_native_parse]

def f(*, # type: int # E: Bare * has associated type comment
x # type: str
Expand Down Expand Up @@ -194,7 +194,7 @@ def f(x, y): # E: Type signature has too few parameters
f(1, 2)
f(1) # E: Missing positional argument "y" in call to "f"

[case testFasterParseTypeErrorCustom]
[case testFasterParseTypeErrorCustom_no_native_parse]

from typing import TypeVar, Generic
T = TypeVar('T')
Expand Down Expand Up @@ -275,7 +275,7 @@ def f7(x: int): # E: Function has duplicate type signatures
# type: (int) -> int
pass

[case testFastParserDuplicateNames]
[case testFastParserDuplicateNames_no_native_parse]

def f(x, y, z):
pass
Expand Down
8 changes: 4 additions & 4 deletions test-data/unit/check-functions.test
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ class A:
main:6: error: Incompatible types in assignment (expression has type "int", variable has type "A")
main:8: error: Argument 1 to "g" has incompatible type "A"; expected "int"

[case testNestedFunctionInMethodWithTooFewArgumentsInTypeComment]
[case testNestedFunctionInMethodWithTooFewArgumentsInTypeComment_no_native_parse]
class A:
def f(self):
# type: () -> None
Expand All @@ -795,7 +795,7 @@ class A:
arg.B # E: "object" has no attribute "B"
[file mod.py]

[case testDeepNestedFunctionWithTooFewArgumentsInTypeComment]
[case testDeepNestedFunctionWithTooFewArgumentsInTypeComment_no_native_parse]
class A:
def f(self):
# type: () -> None
Expand Down Expand Up @@ -2139,13 +2139,13 @@ class A:
pass
[builtins fixtures/staticmethod.pyi]

[case testEllipsisWithSomethingAfterItFails]
[case testEllipsisWithSomethingAfterItFails_no_native_parse]
def f(x, y, z): # type: (..., int) -> None
pass
[out]
main:1: error: Ellipses cannot accompany other parameter types in function type signature

[case testEllipsisWithSomethingBeforeItFails]
[case testEllipsisWithSomethingBeforeItFails_no_native_parse]
def f(x, y, z): # type: (int, ...) -> None
pass
[out]
Expand Down
4 changes: 2 additions & 2 deletions test-data/unit/check-ignore.test
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ from xyz_m import * # type: ignore
x # E: Name "x" is not defined
1() # E: "int" not callable

[case testIgnoreImportBadModule]
[case testIgnoreImportBadModule_no_native_parse]
import m # type: ignore
from m import a # type: ignore
[file m.py]
Expand All @@ -54,7 +54,7 @@ foo = 3
[builtins fixtures/module_all.pyi]
[out]

[case testIgnoreImportStarFromBadModule]
[case testIgnoreImportStarFromBadModule_no_native_parse]
from m import * # type: ignore
[file m.py]
+
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/check-incremental.test
Original file line number Diff line number Diff line change
Expand Up @@ -7264,7 +7264,7 @@ bar: int = foo
[out3]
tmp/bar.py:2: error: Incompatible types in assignment (expression has type "str", variable has type "int")

[case testIncrementalBlockingErrorRepeatAndUndo]
[case testIncrementalBlockingErrorRepeatAndUndo_no_native_parse]
import m
[file m.py]
import f
Expand Down
Loading