From d81aad4fa1182eccfe1ca4b73801e3d994a11bb5 Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Sun, 9 Aug 2026 18:34:18 +0100 Subject: [PATCH 1/3] [WIP] Make native parser the default --- mypy/main.py | 4 +- mypy/options.py | 4 +- mypy/test/testfinegrained.py | 6 ++ mypy/test/testsemanal.py | 6 ++ mypy/test/teststubtest.py | 2 +- test-data/unit/cmdline.test | 12 ++-- test-data/unit/fine-grained-blockers.test | 70 +++++++++++------------ test-data/unit/fine-grained-suggest.test | 4 +- test-data/unit/outputjson.test | 2 +- test-data/unit/parse.test | 12 ++-- test-data/unit/semanal-errors.test | 38 ++++++------ test-data/unit/semanal-statements.test | 2 +- 12 files changed, 85 insertions(+), 77 deletions(-) diff --git a/mypy/main.py b/mypy/main.py index 0cf624a3a5d7b..e16a59c6fdb13 100644 --- a/mypy/main.py +++ b/mypy/main.py @@ -1296,10 +1296,10 @@ def add_invertible_flag( dest="local_partial_types", help=argparse.SUPPRESS, ) - # --native-parser enables the native parser (experimental) + # --native-parser enables the native parser. add_invertible_flag( "--native-parser", - default=False, + default=True, help="Enable faster parser that parses directly to mypy AST", ) # --logical-deps adds some more dependencies that are not semantically needed, but diff --git a/mypy/options.py b/mypy/options.py index 92c9ea3b1701d..88f8e674ed2e7 100644 --- a/mypy/options.py +++ b/mypy/options.py @@ -385,8 +385,8 @@ def __init__(self) -> None: self.logical_deps = False # If True, partial types can't span a module top level and a function self.local_partial_types = True - # If True, use the native parser (experimental) - self.native_parser = False + # If True, use the native parser + self.native_parser = True # Some behaviors are changed when using Bazel (https://bazel.build). self.bazel = False # If True, export inferred types for all expressions as BuildResult.types diff --git a/mypy/test/testfinegrained.py b/mypy/test/testfinegrained.py index 8a93018e39b32..809386117eb37 100644 --- a/mypy/test/testfinegrained.py +++ b/mypy/test/testfinegrained.py @@ -44,6 +44,8 @@ ) # Set to True to perform (somewhat expensive) checks for duplicate AST nodes after merge +from mypy.test.update_data import update_testcase_output + CHECK_CONSISTENCY = False @@ -130,6 +132,10 @@ def run_case(self, testcase: DataDrivenTestCase) -> None: # Normalize paths in test output (for Windows). a = [line.replace("\\", "/") for line in a] + # This may not work perfectly, since it was designed for testcheck.py, use with care. + if testcase.output != a and testcase.config.getoption("--update-data", False): + update_testcase_output(testcase, a, incremental_step=1) + assert_string_arrays_equal( testcase.output, a, f"Invalid output ({testcase.file}, line {testcase.line})" ) diff --git a/mypy/test/testsemanal.py b/mypy/test/testsemanal.py index e11a25617fa48..a66280aea5e56 100644 --- a/mypy/test/testsemanal.py +++ b/mypy/test/testsemanal.py @@ -21,6 +21,7 @@ # Semantic analyzer test cases: dump parse tree # Semantic analysis test case description files. +from mypy.test.update_data import update_testcase_output from mypy.types import TypeStrVisitor semanal_files = find_test_files( @@ -112,6 +113,11 @@ def test_semanal_error(testcase: DataDrivenTestCase) -> None: a = e.messages if testcase.normalize_output: a = normalize_error_messages(a) + + # This may not work perfectly, since it was designed for testcheck.py, use with care. + if testcase.output != a and testcase.config.getoption("--update-data", False): + update_testcase_output(testcase, a, incremental_step=1) + assert_string_arrays_equal( testcase.output, a, f"Invalid compiler output ({testcase.file}, line {testcase.line})" ) diff --git a/mypy/test/teststubtest.py b/mypy/test/teststubtest.py index 2db149ce65c97..d6324dedec75f 100644 --- a/mypy/test/teststubtest.py +++ b/mypy/test/teststubtest.py @@ -3207,7 +3207,7 @@ def test_mypy_build(self) -> None: output = run_stubtest(stub="+", runtime="", options=[]) assert output == ( "error: not checking stubs due to failed mypy compile:\n{}.pyi:1: " - "error: Invalid syntax [syntax]\n".format(TEST_MODULE_NAME) + "error: Expected an expression [syntax]\n".format(TEST_MODULE_NAME) ) output = run_stubtest(stub="def f(): ...\ndef f(): ...", runtime="", options=[]) diff --git a/test-data/unit/cmdline.test b/test-data/unit/cmdline.test index 7066034b3e39c..41dd3bdb3da7d 100644 --- a/test-data/unit/cmdline.test +++ b/test-data/unit/cmdline.test @@ -760,7 +760,7 @@ some_file.py:11: error: Argument 1 to "some_interesting_method" of [file some_file.py] it_looks_like_we_started_typing_something_but_then. = did_not_notice(an_extra_dot) [out] -some_file.py:1: error: Invalid syntax [syntax] +some_file.py:1: error: Expected an identifier [syntax] ...ooks_like_we_started_typing_something_but_then. = did_not_notice(an_ex... ^ == Return code: 2 @@ -905,12 +905,10 @@ public static void main(String[] args) [file pkg/y.py] x: str = 0 [out] -pkg/x.py:1: error: Invalid syntax. Perhaps you forgot a comma? -Found 1 error in 1 file (errors prevented further checking) -== Return code: 2 -[out version>=3.10.3] -pkg/x.py:1: error: Invalid syntax -Found 1 error in 1 file (errors prevented further checking) +pkg/x.py:1: error: Simple statements must be separated by newlines or semicolons +pkg/x.py:1: error: Expected index or slice expression +pkg/x.py:1: error: Expected `,`, found name +Found 3 errors in 1 file (errors prevented further checking) == Return code: 2 [case testCmdlinePackageAndFile] diff --git a/test-data/unit/fine-grained-blockers.test b/test-data/unit/fine-grained-blockers.test index 1bb1b3c44d2f4..24e26e145a36b 100644 --- a/test-data/unit/fine-grained-blockers.test +++ b/test-data/unit/fine-grained-blockers.test @@ -19,7 +19,7 @@ def f(x: int) -> None: pass def f() -> None: pass [out] == -a.py:1: error: Expected ':' +a.py:1: error: Expected an expression == main:2: error: Missing positional argument "x" in call to "f" == @@ -38,9 +38,9 @@ def f(x: int) -> None: pass def f() -> None: pass [out] == -a.py:1: error: Expected ':' [syntax] +a.py:1: error: Expected an expression [syntax] def f(x: int) -> - ^ + ^ == main:3: error: Missing positional argument "x" in call to "f" [call-arg] a.f() @@ -61,9 +61,9 @@ def f(x: int def f(x: int) -> None: pass [out] == -a.py:1: error: Expected ':' +a.py:1: error: Expected an expression == -a.py:2: error: Expected ':' +a.py:2: error: Expected `:`, found newline == main:2: error: Missing positional argument "x" in call to "f" @@ -101,7 +101,7 @@ def f() -> None: pass main:3: error: Too many arguments for "f" main:5: error: Too many arguments for "f" == -a.py:1: error: Expected ':' +a.py:1: error: Expected `:`, found newline == main:3: error: Too many arguments for "f" main:5: error: Too many arguments for "f" @@ -122,12 +122,12 @@ class C: def f(self, x: int) -> None: pass [out] == -a.py:1: error: Invalid syntax +a.py:1: error: Simple statements must be separated by newlines or semicolons == main:5: error: Missing positional argument "x" in call to "f" of "C" [out version==3.10.0] == -a.py:1: error: Invalid syntax. Perhaps you forgot a comma? +a.py:1: error: Simple statements must be separated by newlines or semicolons == main:5: error: Missing positional argument "x" in call to "f" of "C" @@ -142,14 +142,14 @@ def f() -> None: pass main:1: error: Cannot find implementation or library stub for module named "a" main:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports == -a.py:1: error: Invalid syntax +a.py:1: error: Simple statements must be separated by newlines or semicolons == main:2: error: Too many arguments for "f" [out version==3.10.0] main:1: error: Cannot find implementation or library stub for module named "a" main:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports == -a.py:1: error: Invalid syntax. Perhaps you forgot a comma? +a.py:1: error: Simple statements must be separated by newlines or semicolons == main:2: error: Too many arguments for "f" @@ -177,7 +177,7 @@ a.f() def g() -> None: pass [out] == -b.py:1: error: Invalid syntax +b.py:1: error: Expected `,`, found name == [case testModifyTwoFilesOneWithBlockingError2] @@ -204,7 +204,7 @@ def f() -> None: pass b.g() [out] == -a.py:1: error: Invalid syntax +a.py:1: error: Expected `,`, found name == [case testBlockingErrorRemainsUnfixed] @@ -223,16 +223,16 @@ import b b.f() [out] == -a.py:1: error: Invalid syntax +a.py:1: error: Simple statements must be separated by newlines or semicolons == -a.py:1: error: Invalid syntax +a.py:1: error: Simple statements must be separated by newlines or semicolons == a.py:2: error: Missing positional argument "x" in call to "f" [out version==3.10.0] == -a.py:1: error: Invalid syntax. Perhaps you forgot a comma? +a.py:1: error: Simple statements must be separated by newlines or semicolons == -a.py:1: error: Invalid syntax. Perhaps you forgot a comma? +a.py:1: error: Simple statements must be separated by newlines or semicolons == a.py:2: error: Missing positional argument "x" in call to "f" @@ -272,9 +272,9 @@ def g() -> None: pass a.f(1) [out] == -a.py:1: error: Invalid syntax +a.py:1: error: Expected `,`, found name == -a.py:1: error: Invalid syntax +a.py:1: error: Expected `,`, found name == a.py:3: error: Too many arguments for "g" b.py:3: error: Too many arguments for "f" @@ -294,14 +294,14 @@ x x [delete a.py.3] [out] == -a.py:1: error: Invalid syntax +a.py:1: error: Simple statements must be separated by newlines or semicolons == main:1: error: Cannot find implementation or library stub for module named "a" main:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports b.py:1: error: Cannot find implementation or library stub for module named "a" [out version==3.10.0] == -a.py:1: error: Invalid syntax. Perhaps you forgot a comma? +a.py:1: error: Simple statements must be separated by newlines or semicolons == main:1: error: Cannot find implementation or library stub for module named "a" main:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports @@ -322,14 +322,14 @@ x x [delete a.py.3] [out] == -a.py:1: error: Invalid syntax +a.py:1: error: Simple statements must be separated by newlines or semicolons == b.py:1: error: Cannot find implementation or library stub for module named "a" b.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports main:1: error: Cannot find implementation or library stub for module named "a" [out version==3.10.0] == -a.py:1: error: Invalid syntax. Perhaps you forgot a comma? +a.py:1: error: Simple statements must be separated by newlines or semicolons == b.py:1: error: Cannot find implementation or library stub for module named "a" b.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports @@ -351,17 +351,17 @@ a.f() [builtins fixtures/module.pyi] [out] == -a.py:1: error: Invalid syntax +a.py:1: error: Simple statements must be separated by newlines or semicolons == -a.py:1: error: Invalid syntax +a.py:1: error: Simple statements must be separated by newlines or semicolons == b.py:2: error: Module has no attribute "f" b.py:3: error: "int" not callable [out version==3.10.0] == -a.py:1: error: Invalid syntax. Perhaps you forgot a comma? +a.py:1: error: Simple statements must be separated by newlines or semicolons == -a.py:1: error: Invalid syntax. Perhaps you forgot a comma? +a.py:1: error: Simple statements must be separated by newlines or semicolons == b.py:2: error: Module has no attribute "f" b.py:3: error: "int" not callable @@ -377,12 +377,12 @@ import blocker def f() -> None: pass [out] == -/test-data/unit/lib-stub/blocker.pyi:2: error: Invalid syntax +/test-data/unit/lib-stub/blocker.pyi:2: error: Simple statements must be separated by newlines or semicolons == a.py:1: error: "int" not callable [out version==3.10.0] == -/test-data/unit/lib-stub/blocker.pyi:2: error: Invalid syntax. Perhaps you forgot a comma? +/test-data/unit/lib-stub/blocker.pyi:2: error: Simple statements must be separated by newlines or semicolons == a.py:1: error: "int" not callable @@ -454,16 +454,16 @@ import sys [builtins fixtures/tuple.pyi] [out] == -a.py:1: error: Invalid syntax +a.py:1: error: Simple statements must be separated by newlines or semicolons == -/test-data/unit/lib-stub/blocker.pyi:2: error: Invalid syntax +/test-data/unit/lib-stub/blocker.pyi:2: error: Simple statements must be separated by newlines or semicolons == a.py:2: error: "int" not callable [out version==3.10.0] == -a.py:1: error: Invalid syntax. Perhaps you forgot a comma? +a.py:1: error: Simple statements must be separated by newlines or semicolons == -/test-data/unit/lib-stub/blocker.pyi:2: error: Invalid syntax. Perhaps you forgot a comma? +/test-data/unit/lib-stub/blocker.pyi:2: error: Simple statements must be separated by newlines or semicolons == a.py:2: error: "int" not callable @@ -480,12 +480,12 @@ x = 1 def f() -> int: return 0 [out] -a.py:1: error: Invalid syntax +a.py:1: error: Simple statements must be separated by newlines or semicolons == b.py:2: error: Incompatible return value type (got "str", expected "int") == [out version==3.10.0] -a.py:1: error: Invalid syntax. Perhaps you forgot a comma? +a.py:1: error: Simple statements must be separated by newlines or semicolons == b.py:2: error: Incompatible return value type (got "str", expected "int") == @@ -532,6 +532,6 @@ a.f(1) [file a.py.2] def f(x: str) -> None: ... [out] -a.py: error: Cannot decode file: 'ascii' codec can't decode byte 0xc3 in position 16: ordinal not in range(128) +main:3: error: "object" has no attribute "f" == main:3: error: Argument 1 to "f" has incompatible type "int"; expected "str" diff --git a/test-data/unit/fine-grained-suggest.test b/test-data/unit/fine-grained-suggest.test index 499a0b4a76fd7..5f83e3f35d3c8 100644 --- a/test-data/unit/fine-grained-suggest.test +++ b/test-data/unit/fine-grained-suggest.test @@ -1117,10 +1117,10 @@ def foo(): ( [out] -foo.py:4: error: '(' was never closed +foo.py:4: error: Unexpected EOF while parsing Command 'suggest' is only valid after a 'check' command (that produces no parse errors) == -foo.py:4: error: '(' was never closed +foo.py:4: error: Unexpected EOF while parsing -- ) [case testSuggestRefine] diff --git a/test-data/unit/outputjson.test b/test-data/unit/outputjson.test index ec716d97b8f1e..1473e4bc27755 100644 --- a/test-data/unit/outputjson.test +++ b/test-data/unit/outputjson.test @@ -56,7 +56,7 @@ foo(1) # flags: --output=json klass foo [out] -{"file": "main", "line": 2, "column": 7, "end_line": 2, "end_column": 8, "message": "Invalid syntax", "hint": null, "code": "syntax", "severity": "error"} +{"file": "main", "line": 2, "column": 7, "end_line": 2, "end_column": 8, "message": "Simple statements must be separated by newlines or semicolons", "hint": null, "code": "syntax", "severity": "error"} !!! Mypy crashed !!! [case testOutputJsonSyntaxErrorParallel] diff --git a/test-data/unit/parse.test b/test-data/unit/parse.test index 1e43600e56898..22dce419f7d69 100644 --- a/test-data/unit/parse.test +++ b/test-data/unit/parse.test @@ -948,20 +948,18 @@ MypyFile:1( [case testNotAsBinaryOp] x not y [out] -main:1: error: Invalid syntax -[out version==3.10.0] -main:1: error: Invalid syntax. Perhaps you forgot a comma? +main:1: error: Simple statements must be separated by newlines or semicolons [case testNotIs] -x not is y # E: Invalid syntax +x not is y [out] +main:1: error: Simple statements must be separated by newlines or semicolons +main:1: error: Expected an identifier, but found a keyword `is` that cannot be used here [case testBinaryNegAsBinaryOp] 1 ~ 2 [out] -main:1: error: Invalid syntax -[out version==3.10.0] -main:1: error: Invalid syntax. Perhaps you forgot a comma? +main:1: error: Simple statements must be separated by newlines or semicolons [case testSliceInList] x = [1, 2][1:2] diff --git a/test-data/unit/semanal-errors.test b/test-data/unit/semanal-errors.test index 7e1f737c61b21..62669ed3f1fc7 100644 --- a/test-data/unit/semanal-errors.test +++ b/test-data/unit/semanal-errors.test @@ -398,70 +398,70 @@ main:2: error: "yield" outside function [case testInvalidLvalues1] 1 = 1 [out] -main:1: error: Cannot assign to literal here. Maybe you meant '==' instead of '='? +main:1: error: Invalid assignment target [case testInvalidLvalues2] (1) = 1 [out] -main:1: error: Cannot assign to literal here. Maybe you meant '==' instead of '='? +main:1: error: Invalid assignment target [case testInvalidLvalues3] (1, 1) = 1 [out] -main:1: error: Cannot assign to literal +main:1: error: Invalid assignment target [case testInvalidLvalues4] [1, 1] = 1 [out] -main:1: error: Cannot assign to literal +main:1: error: Invalid assignment target [case testInvalidLvalues6] x = y = z = 1 # ok x, (y, 1) = 1 [out] -main:2: error: Cannot assign to literal +main:2: error: Invalid assignment target [case testInvalidLvalues7] x, [y, 1] = 1 [out] -main:1: error: Cannot assign to literal +main:1: error: Invalid assignment target [case testInvalidLvalues8] x, [y, [z, 1]] = 1 [out] -main:1: error: Cannot assign to literal +main:1: error: Invalid assignment target [case testInvalidLvalues9] x, (y) = 1 # ok x, (y, (z, z)) = 1 # ok x, (y, (z, 1)) = 1 [out] -main:3: error: Cannot assign to literal +main:3: error: Invalid assignment target [case testInvalidLvalues10] x + x = 1 [out] -main:1: error: Cannot assign to expression here. Maybe you meant '==' instead of '='? +main:1: error: Invalid assignment target [case testInvalidLvalues11] -x = 1 [out] -main:1: error: Cannot assign to expression here. Maybe you meant '==' instead of '='? +main:1: error: Invalid assignment target [case testInvalidLvalues12] 1.1 = 1 [out] -main:1: error: Cannot assign to literal here. Maybe you meant '==' instead of '='? +main:1: error: Invalid assignment target [case testInvalidLvalues13] 'x' = 1 [out] -main:1: error: Cannot assign to literal here. Maybe you meant '==' instead of '='? +main:1: error: Invalid assignment target [case testInvalidLvalues14] x() = 1 [out] -main:1: error: Cannot assign to function call here. Maybe you meant '==' instead of '='? +main:1: error: Invalid assignment target [case testTwoStarExpressions] a, *b, *c = 1 @@ -515,13 +515,13 @@ main:2: error: can't use starred expression here x = 1 del x(1) [out] -main:2: error: Cannot delete function call +main:2: error: Invalid delete target [case testInvalidDel2] x = 1 del x + 1 [out] -main:2: error: Cannot delete expression +main:2: error: Invalid delete target [case testInvalidDel3] del z # E: Name "z" is not defined @@ -902,7 +902,7 @@ import typing def f(): pass f() = 1 # type: int [out] -main:3: error: Cannot assign to function call here. Maybe you meant '==' instead of '='? +main:3: error: Invalid assignment target [case testIndexedAssignmentWithTypeDeclaration] import typing @@ -978,7 +978,7 @@ x, y = 1, 2 # type: int # E: Tuple type expected for multiple variables a = 1 a() = None # type: int [out] -main:2: error: Cannot assign to function call here. Maybe you meant '==' instead of '='? +main:2: error: Invalid assignment target [case testInvalidLvalueWithExplicitType2] a = 1 @@ -1306,7 +1306,7 @@ main:2: note: Did you forget to import it from "typing"? (Suggestion: "from typi def f(): pass with f() as 1: pass [out] -main:2: error: Cannot assign to literal +main:2: error: Invalid assignment target [case testInvalidTypeAnnotation] import typing @@ -1320,7 +1320,7 @@ import typing def f() -> None: f() = 1 # type: int [out] -main:3: error: Cannot assign to function call here. Maybe you meant '==' instead of '='? +main:3: error: Invalid assignment target [case testInvalidReferenceToAttributeOfOuterClass] class A: diff --git a/test-data/unit/semanal-statements.test b/test-data/unit/semanal-statements.test index 13999c4ed02d2..4f377236d74db 100644 --- a/test-data/unit/semanal-statements.test +++ b/test-data/unit/semanal-statements.test @@ -557,7 +557,7 @@ MypyFile:1( def f(x, y) -> None: del x, y + 1 [out] -main:2: error: Cannot delete expression +main:2: error: Invalid delete target [case testTry] class c: pass From 049c5fe32c3730efbfed49d242f0d2ae35292df1 Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Sun, 9 Aug 2026 19:23:13 +0100 Subject: [PATCH 2/3] Also update parse error test output --- mypy/test/testparse.py | 6 ++ test-data/unit/parse-errors.test | 100 ++++++++++++++++++------------- 2 files changed, 65 insertions(+), 41 deletions(-) diff --git a/mypy/test/testparse.py b/mypy/test/testparse.py index 8f4de5bc7412b..3d4de307b7ad5 100644 --- a/mypy/test/testparse.py +++ b/mypy/test/testparse.py @@ -13,6 +13,7 @@ from mypy.parse import parse from mypy.test.data import DataDrivenTestCase, DataSuite from mypy.test.helpers import assert_string_arrays_equal, find_test_files, parse_options +from mypy.test.update_data import update_testcase_output from mypy.util import get_mypy_comments @@ -115,6 +116,11 @@ def test_parse_error(testcase: DataDrivenTestCase) -> None: except CompileError as e: if e.module_with_blocker is not None: assert e.module_with_blocker == "__main__" + + # This may not work perfectly, since it was designed for testcheck.py, use with care. + if testcase.output != e.messages and testcase.config.getoption("--update-data", False): + update_testcase_output(testcase, e.messages, incremental_step=1) + # Verify that there was a compile error and that the error messages # are equivalent. assert_string_arrays_equal( diff --git a/test-data/unit/parse-errors.test b/test-data/unit/parse-errors.test index 23e24ea034e83..5625b8f4f383c 100644 --- a/test-data/unit/parse-errors.test +++ b/test-data/unit/parse-errors.test @@ -18,14 +18,16 @@ file:1: error: Expected ':' 1 2 [out] -file:2: error: Unexpected indent +file:2: error: Unexpected indentation +file:2: error: Expected a statement [case testInconsistentIndent] if x: 1 1 [out] -file:3: error: Unexpected indent +file:3: error: Unexpected indentation +file:3: error: Expected a statement [case testInconsistentIndent2] if x: @@ -33,81 +35,85 @@ if x: 1 [out] file:3: error: Unindent does not match any outer indentation level +file:3: error: Expected dedent, found end of file [case testInvalidBinaryOp] 1> a* a+1* [out] -file:1: error: Invalid syntax +file:1: error: Expected an expression +file:2: error: Expected an expression +file:3: error: Expected an expression [case testDoubleStar] **a [out] -file:1: error: Invalid syntax +file:1: error: Expected an expression [case testMissingSuperClass] class A(: pass [out] -file:1: error: Invalid syntax +file:1: error: Expected an expression or a ')' +file:1: error: Expected `)`, found newline [case testUnexpectedEof] if 1: [out] -file:1: error: Expected an indented block after 'if' statement on line 1 +file:1: error: Expected an indented block after `if` statement [case testInvalidKeywordArguments1] f(x=y, z) [out] -file:1: error: Positional argument follows keyword argument +file:1: error: Positional argument cannot follow keyword argument [case testInvalidKeywordArguments2] f(**x, y) [out] -file:1: error: Positional argument follows keyword argument unpacking +file:1: error: Positional argument cannot follow keyword argument unpacking [case testInvalidBareAsteriskAndVarArgs2] def f(*x: A, *) -> None: pass [out] -file:1: error: Invalid syntax +file:1: error: Keyword-only parameter separator not allowed after '*' parameter [case testInvalidBareAsteriskAndVarArgs3] def f(*, *x: A) -> None: pass [out] -file:1: error: Invalid syntax +file:1: error: Only one '*' parameter allowed [case testInvalidBareAsteriskAndVarArgs4] def f(*, **x: A) -> None: pass [out] -file:1: error: Named arguments must follow bare * +file:1: error: Expected one or more keyword parameter after `*` separator [case testInvalidBareAsterisk1] def f(*) -> None: pass [out] -file:1: error: Named arguments must follow bare * +file:1: error: Expected one or more keyword parameter after `*` separator [case testInvalidBareAsterisk2] def f(x, *) -> None: pass [out] -file:1: error: Named arguments must follow bare * +file:1: error: Expected one or more keyword parameter after `*` separator [case testInvalidFuncDefArgs1] def f(x = y, x): pass [out] -file:1: error: Non-default argument follows default argument +file:1: error: Parameter without a default cannot follow a parameter with a default [case testInvalidFuncDefArgs3] def f(**x, y): pass [out] -file:1: error: Invalid syntax +file:1: error: Parameter cannot follow var-keyword parameter [case testInvalidFuncDefArgs4] def f(**x, y=x): pass [out] -file:1: error: Invalid syntax +file:1: error: Parameter cannot follow var-keyword parameter [case testInvalidTypeComment] 0 @@ -154,7 +160,7 @@ file:2: error: Syntax error in type comment "A B" [case testMissingBracket] def foo( [out] -file:1: error: '(' was never closed +file:1: error: Unexpected EOF while parsing [case testInvalidSignatureInComment1] def f(): # type: x @@ -203,7 +209,7 @@ file:1: error: Syntax error in type comment "(x) -" def f(): # type: (x) -> pass [out] -file:1: error: Syntax error in type comment "(x) ->" +file:1: error: Type signature has too many parameters [case testInvalidSignatureInComment9] def f(): # type: (x) -> . @@ -281,96 +287,103 @@ file:3: error: Inconsistent use of "**" in function signature [case testPrintStatementInPython3] print 1 [out] -file:1: error: Missing parentheses in call to 'print'. Did you mean print(...)? +file:1: error: Simple statements must be separated by newlines or semicolons [case testInvalidConditionInConditionalExpression] 1 if 2, 3 else 4 [out] -file:1: error: Expected 'else' after 'if' expression +file:1: error: Expected `else`, found `,` +file:1: error: Expected a statement [case testInvalidConditionInConditionalExpression2] 1 if x for y in z else 4 [out] -file:1: error: Expected 'else' after 'if' expression +file:1: error: Expected `else`, found `for` +file:1: error: Simple statements must be separated by newlines or semicolons +file:1: error: Expected a statement [case testInvalidConditionInConditionalExpression3] 1 if x else for y in z [out] -file:1: error: Invalid syntax +file:1: error: Expected an identifier, but found a keyword `for` that cannot be used here +file:1: error: Simple statements must be separated by newlines or semicolons [case testYieldFromNotRightParameter] def f(): yield from [out] -file:2: error: Invalid syntax +file:2: error: Expected an expression [case testYieldFromAfterReturn] def f(): return yield from h() [out] -file:2: error: Invalid syntax +file:2: error: Yield expression cannot be used here [case testImportDotModule] import .x [out] -file:1: error: Invalid syntax +file:1: error: Expected an import name [case testImportDot] import . [out] -file:1: error: Invalid syntax +file:1: error: Expected an import name +file:1: error: Expected one or more symbol names after import [case testInvalidFunctionName] def while(): pass [out] -file:1: error: Invalid syntax +file:1: error: Expected an identifier, but found a keyword `while` that cannot be used here [case testInvalidEllipsis1] ...0 ..._ ...a [out] -file:1: error: Invalid syntax +file:1: error: Simple statements must be separated by newlines or semicolons +file:2: error: Simple statements must be separated by newlines or semicolons +file:3: error: Simple statements must be separated by newlines or semicolons [case testBlockStatementInSingleLineIf] if 1: if 2: pass [out] -file:1: error: Invalid syntax +file:1: error: Expected a simple statement [case testBlockStatementInSingleLineIf2] if 1: while 2: pass [out] -file:1: error: Invalid syntax +file:1: error: Expected a simple statement [case testBlockStatementInSingleLineIf3] if 1: for x in y: pass [out] -file:1: error: Invalid syntax +file:1: error: Expected a simple statement [case testUnexpectedEllipsis] a = a... [out] -file:1: error: Invalid syntax +file:1: error: Simple statements must be separated by newlines or semicolons [case testParseErrorBeforeUnicodeLiteral] x u'y' [out] -file:1: error: Invalid syntax +file:1: error: Simple statements must be separated by newlines or semicolons [case testParseErrorInExtendedSlicing] x[:, [out] -file:1: error: '[' was never closed +file:1: error: Unexpected EOF while parsing [case testParseErrorInExtendedSlicing2] x[:,:: [out] -file:1: error: '[' was never closed +file:1: error: Unexpected EOF while parsing [case testParseErrorInExtendedSlicing3] x[:,: [out] -file:1: error: '[' was never closed +file:1: error: Unexpected EOF while parsing [case testInvalidEncoding] # foo @@ -407,17 +420,19 @@ file:0: error: Unknown encoding: uft8 2L 0x2L [out] -file:1: error: Invalid decimal literal +file:1: error: Simple statements must be separated by newlines or semicolons +file:2: error: Simple statements must be separated by newlines or semicolons [case testPython2LegacyInequalityInPython3] 1 <> 2 [out] -file:1: error: Invalid syntax +file:1: error: Expected an expression [case testLambdaInListComprehensionInPython3] ([ 0 for x in 1, 2 if 3 ]) [out] -file:1: error: Invalid syntax +file:1: error: Expected `]`, found `,` +file:1: error: Expected `else`, found `]` [case testTupleArgListInPython3] def f(x, (y, z)): pass @@ -427,12 +442,15 @@ file:1: error: Invalid syntax [case testBackquoteInPython3] `1 + 2` [out] -file:1: error: Invalid syntax +file:1: error: Got unexpected token ` +file:1: error: Expected a statement [case testSmartQuotes] foo = ‘bar’ [out] -file:1: error: Invalid character '‘' (U+2018) +file:1: error: Got unexpected token ‘ +file:1: error: Got unexpected token ’ +file:1: error: Expected a statement [case testExceptCommaInPython3] try: From 86a897a73c19496af42934a3d52d508f5e6a98eb Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Wed, 19 Aug 2026 15:06:50 +0100 Subject: [PATCH 3/3] Re-enable and update some more tests --- mypy/test/testcheck.py | 6 +++--- mypy/test/testdeps.py | 3 +++ mypy/test/testfinegrained.py | 5 +++++ mypy/test/testsemanal.py | 3 +++ test-data/unit/check-async-await.test | 8 ++++---- test-data/unit/check-basic.test | 5 +++-- test-data/unit/check-columns.test | 13 ++++++------- test-data/unit/check-errorcodes.test | 20 +++++++++----------- test-data/unit/check-expressions.test | 11 +++++------ test-data/unit/check-fastparse.test | 22 +++++++--------------- test-data/unit/check-functions.test | 8 ++++---- test-data/unit/check-ignore.test | 8 ++++---- test-data/unit/check-incremental.test | 6 +++--- test-data/unit/check-literal.test | 9 ++++----- test-data/unit/check-namedtuple.test | 2 +- test-data/unit/check-newsemanal.test | 2 +- test-data/unit/check-newsyntax.test | 7 ++++--- test-data/unit/check-overloading.test | 2 +- test-data/unit/check-python312.test | 6 +++--- test-data/unit/check-python39.test | 4 ++-- test-data/unit/check-statements.test | 21 ++++++++------------- test-data/unit/check-type-aliases.test | 8 ++++---- test-data/unit/check-typeddict.test | 8 ++++---- test-data/unit/check-unreachable-code.test | 6 +++--- test-data/unit/deps-statements.test | 4 ++-- test-data/unit/fine-grained.test | 4 ++-- test-data/unit/semanal-classvar.test | 8 ++++---- 27 files changed, 102 insertions(+), 107 deletions(-) diff --git a/mypy/test/testcheck.py b/mypy/test/testcheck.py index f2bd21b87debf..3eba4bd0047ae 100644 --- a/mypy/test/testcheck.py +++ b/mypy/test/testcheck.py @@ -137,7 +137,6 @@ def run_case_once( options = parse_options(original_program_text, testcase, incremental_step) options.use_builtins_fixtures = True options.show_traceback = True - options.native_parser = bool(os.environ.get("TEST_NATIVE_PARSER")) options.reveal_verbose_types = not testcase.name.endswith("_no_verbose_reveal") if options.num_workers: @@ -152,8 +151,9 @@ def run_case_once( if testcase.name.endswith("_parallel_only"): raise pytest.skip("Test is only for parallel mode") - if options.native_parser and testcase.name.endswith("_no_native_parse"): - raise pytest.skip("Test not supported by native parser yet") + if testcase.name.endswith("_old_parser"): + # This test is only for the old parser. + options.native_parser = False # Enable some options automatically based on test file name. if "columns" in testcase.file: diff --git a/mypy/test/testdeps.py b/mypy/test/testdeps.py index 7c845eab8b572..bd1ee7cf41ab8 100644 --- a/mypy/test/testdeps.py +++ b/mypy/test/testdeps.py @@ -39,6 +39,9 @@ def run_case(self, testcase: DataDrivenTestCase) -> None: options.export_types = True options.preserve_asts = True options.allow_empty_bodies = True + if testcase.name.endswith("_old_parser"): + # This test is only for the old parser. + options.native_parser = False messages, files, type_map = self.build(src, options) a = messages if files is None or type_map is None: diff --git a/mypy/test/testfinegrained.py b/mypy/test/testfinegrained.py index 809386117eb37..1f3ff92ce821b 100644 --- a/mypy/test/testfinegrained.py +++ b/mypy/test/testfinegrained.py @@ -161,6 +161,11 @@ def get_options(self, source: str, testcase: DataDrivenTestCase, build_cache: bo options.export_types = "inspect" in testcase.file # Treat empty bodies safely for these test cases. options.allow_empty_bodies = not testcase.name.endswith("_no_empty") + + if testcase.name.endswith("_old_parser"): + # This test is only for the old parser. + options.native_parser = False + options.reveal_verbose_types = True if re.search("flags:.*--follow-imports", source) is None: # Override the default for follow_imports diff --git a/mypy/test/testsemanal.py b/mypy/test/testsemanal.py index a66280aea5e56..c261e0b33f5cc 100644 --- a/mypy/test/testsemanal.py +++ b/mypy/test/testsemanal.py @@ -64,6 +64,9 @@ def test_semanal(testcase: DataDrivenTestCase) -> None: src = "\n".join(testcase.input) options = get_semanal_options(src, testcase) options.python_version = testfile_pyversion(testcase.file) + if testcase.name.endswith("_old_parser"): + # This test is only for the old parser. + options.native_parser = False result = build.build( sources=[BuildSource("main", None, src)], options=options, alt_lib_path=test_temp_dir ) diff --git a/test-data/unit/check-async-await.test b/test-data/unit/check-async-await.test index e6675e864db06..9b0e91f35a31f 100644 --- a/test-data/unit/check-async-await.test +++ b/test-data/unit/check-async-await.test @@ -192,8 +192,8 @@ async def f() -> None: [builtins fixtures/async_await.pyi] [typing fixtures/typing-async.pyi] -[case testAsyncForTypeComments_no_native_parse] - +-- Native parser does not support type comments in `for` and `with` statements. +[case testAsyncForTypeComments_old_parser] from typing import AsyncIterator, Union class C(AsyncIterator[int]): async def __anext__(self) -> int: return 0 @@ -342,8 +342,8 @@ async def f() -> None: [builtins fixtures/async_await.pyi] [typing fixtures/typing-async.pyi] -[case testAsyncWithTypeComments_no_native_parse] - +-- Native parser does not support type comments in `for` and `with` statements. +[case testAsyncWithTypeComments_old_parser] class C: async def __aenter__(self) -> int: pass async def __aexit__(self, x, y, z) -> None: pass diff --git a/test-data/unit/check-basic.test b/test-data/unit/check-basic.test index cfaff2d636e25..0262ea9048f3f 100644 --- a/test-data/unit/check-basic.test +++ b/test-data/unit/check-basic.test @@ -286,10 +286,11 @@ x = 1 x in 1, # E: Unsupported right operand type for in ("int") [builtins fixtures/tuple.pyi] -[case testTrailingCommaInIfParsing_no_native_parse] +[case testTrailingCommaInIfParsing] if x in 1, : pass [out] -main:1: error: Invalid syntax +main:1: error: Expected `:`, found `,` +main:1: error: Expected a statement [case testInitReturnTypeError] class C: diff --git a/test-data/unit/check-columns.test b/test-data/unit/check-columns.test index dd8389c195583..ada3d9dc12b39 100644 --- a/test-data/unit/check-columns.test +++ b/test-data/unit/check-columns.test @@ -1,10 +1,10 @@ # Test column numbers in messages. --show-column-numbers is enabled implicitly by test runner. -[case testColumnsSyntaxError_no_native_parse] +[case testColumnsSyntaxError] f() 1 + [out] -main:2:5: error: Invalid syntax +main:2:5: error: Expected an expression [case testColumnsNestedFunctions] import typing @@ -146,8 +146,7 @@ if int(): def f(a: 'A') -> None: pass (f(b=object())) # E:6: Unexpected keyword argument "b" for "f" -[case testColumnInvalidType_no_native_parse] - +[case testColumnInvalidType] from typing import Iterable bad = 0 @@ -158,8 +157,8 @@ def f(x: bad): # E:10: Variable "__main__.bad" is not valid as a type \ # N:8: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases if int(): - def g(x): # E:5: Variable "__main__.bad" is not valid as a type \ - # N:5: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases + def g(x): # E:11: Variable "__main__.bad" is not valid as a type \ + # N:11: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases # type: (bad) -> None y = 0 # type: bad # E:9: Variable "__main__.bad" is not valid as a type \ # N:9: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases @@ -342,7 +341,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_no_native_parse] +[case testColumnSyntaxErrorInTypeAnnotation2] if int(): # TODO: It would be better to point to the type comment xyz = 0 # type: blurbnard blarb diff --git a/test-data/unit/check-errorcodes.test b/test-data/unit/check-errorcodes.test index 5296d813334e4..05e9a1cf2125a 100644 --- a/test-data/unit/check-errorcodes.test +++ b/test-data/unit/check-errorcodes.test @@ -101,21 +101,19 @@ class A: [case testErrorCodeNoteHasNoCode] reveal_type(1) # N: Revealed type is "Literal[1]?" -[case testErrorCodeSyntaxError_no_native_parse] +[case testErrorCodeSyntaxError] 1 '' [out] -main:1: error: Invalid syntax [syntax] -[out version==3.10.0] -main:1: error: Invalid syntax. Perhaps you forgot a comma? [syntax] +main:1: error: Simple statements must be separated by newlines or semicolons [syntax] -[case testErrorCodeSyntaxError2_no_native_parse] +[case testErrorCodeSyntaxError2] 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_no_native_parse] +[case testErrorCodeSyntaxError3] # 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] \ @@ -281,7 +279,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_no_native_parse] +[case testErrorCodeBadIgnore] 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 @@ -299,7 +297,7 @@ def f(x, # type: int # type: ignore[ # E: Invalid "type: ignore" comment [sy # type: (...) -> None pass -[case testErrorCodeBadIgnoreNoExtraComment_no_native_parse] +[case testErrorCodeBadIgnoreNoExtraComment] # Omit the E: ... comments, as they affect parsing import nostub # type: ignore xyz import nostub # type: ignore[xyz @@ -846,7 +844,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_no_native_parse] +[case testErrorCodeTypeIgnoreMisspelled2] x = y # type: int # type: ignored[foo] x = y # type: int # type: ignored [foo] [out] @@ -1098,7 +1096,7 @@ def f(arg: int) -> int: def f(arg: str) -> str: ... -[case testSliceInDictBuiltin_no_native_parse] +[case testSliceInDictBuiltin] # flags: --show-column-numbers b: dict[int, x:y] c: dict[x:y] @@ -1111,7 +1109,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_no_native_parse] +[case testSliceInDictTyping] # flags: --show-column-numbers from typing import Dict b: Dict[int, x:y] diff --git a/test-data/unit/check-expressions.test b/test-data/unit/check-expressions.test index 0605c2d8a6fe4..1661a79a62758 100644 --- a/test-data/unit/check-expressions.test +++ b/test-data/unit/check-expressions.test @@ -1478,7 +1478,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_no_native_parse] +[case testGeneratorNoSpuriousError] from typing import Iterable, overload @overload @@ -1493,8 +1493,8 @@ take_iterable(reveal_type(1 for _ in [])) # N: Revealed type is "typing.Generato # NOTE: Type is revealed for every overload tried # TODO: Overload shouldn't fail if expression contains an error that shouldn't affect the inferred type. take_iterable(reveal_type(1 if (-"") else 1 for _ in [])) # N: Revealed type is "typing.Generator[builtins.int, None, None]" \ - # N: Revealed type is "typing.Generator[builtins.bool, None, None]" \ # E: Generator has incompatible item type "int"; expected "bool" \ + # N: Revealed type is "typing.Generator[builtins.bool, None, None]" \ # E: Unsupported operand type for unary - ("str") [builtins fixtures/for.pyi] @@ -1937,13 +1937,12 @@ None == None None < None # E: Unsupported left operand type for < ("None") [builtins fixtures/ops.pyi] -[case testDictWithStarExpr_no_native_parse] - -b = {'z': 26, *a} # E: Invalid syntax +[case testDictWithStarExpr] +b = {'z': 26, *a} # E: Starred expression cannot be used here \ + # E: Expected `:`, found `}` [builtins fixtures/dict.pyi] [case testDictWithStarStarExpr] - from typing import Dict, Iterable class Thing: diff --git a/test-data/unit/check-fastparse.test b/test-data/unit/check-fastparse.test index 0897760fb23a7..eada19f7c6e57 100644 --- a/test-data/unit/check-fastparse.test +++ b/test-data/unit/check-fastparse.test @@ -1,31 +1,25 @@ -[case testFastParseSyntaxError_no_native_parse] - -1 + # E: Invalid syntax - -[case testFastParseTypeCommentSyntaxError_no_native_parse] +[case testFastParseSyntaxError] +1 + # E: Expected an expression +[case testFastParseTypeCommentSyntaxError] x = None # type: a : b # E: Syntax error in type comment "a : b" [case testFastParseInvalidTypeComment] - 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_no_native_parse] - +[case testFastParseFunctionAnnotationSyntaxError] def f(): # E: Syntax error in type comment "None -> None" # N: Suggestion: wrap argument types in parentheses # type: None -> None pass -[case testFastParseFunctionAnnotationSyntaxErrorSpaces_no_native_parse] - +[case testFastParseFunctionAnnotationSyntaxErrorSpaces] def f(): # E: Syntax error in type comment "None -> None" # N: Suggestion: wrap argument types in parentheses # type: None -> None pass [case testFastParseInvalidFunctionAnnotation] - def f(x): # E: Invalid type comment or annotation # type: (a + b) -> None pass @@ -156,8 +150,7 @@ def f(a, # type: A [builtins fixtures/dict.pyi] [out] -[case testFastParsePerArgumentAnnotationsWithAnnotatedBareStar_no_native_parse] - +[case testFastParsePerArgumentAnnotationsWithAnnotatedBareStar] def f(*, # type: int # E: Bare * has associated type comment x # type: str ): @@ -286,8 +279,7 @@ def f7(x: int): # E: Function has duplicate type signatures # type: (int) -> int pass -[case testFastParserDuplicateNames_no_native_parse] - +[case testFastParserDuplicateNames] def f(x, y, z): pass diff --git a/test-data/unit/check-functions.test b/test-data/unit/check-functions.test index 893eefb36f874..03426b55836a3 100644 --- a/test-data/unit/check-functions.test +++ b/test-data/unit/check-functions.test @@ -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_no_native_parse] +[case testNestedFunctionInMethodWithTooFewArgumentsInTypeComment] class A: def f(self): # type: () -> None @@ -795,7 +795,7 @@ class A: arg.B # E: "object" has no attribute "B" [file mod.py] -[case testDeepNestedFunctionWithTooFewArgumentsInTypeComment_no_native_parse] +[case testDeepNestedFunctionWithTooFewArgumentsInTypeComment] class A: def f(self): # type: () -> None @@ -2148,13 +2148,13 @@ class A: pass [builtins fixtures/staticmethod.pyi] -[case testEllipsisWithSomethingAfterItFails_no_native_parse] +[case testEllipsisWithSomethingAfterItFails] 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_no_native_parse] +[case testEllipsisWithSomethingBeforeItFails] def f(x, y, z): # type: (int, ...) -> None pass [out] diff --git a/test-data/unit/check-ignore.test b/test-data/unit/check-ignore.test index 2bcf6e0884966..d2f7ef5a029a4 100644 --- a/test-data/unit/check-ignore.test +++ b/test-data/unit/check-ignore.test @@ -32,13 +32,13 @@ from xyz_m import * # type: ignore x # E: Name "x" is not defined 1() # E: "int" not callable -[case testIgnoreImportBadModule_no_native_parse] +[case testIgnoreImportBadModule] import m # type: ignore from m import a # type: ignore [file m.py] + [out] -tmp/m.py:1: error: Invalid syntax +tmp/m.py:1: error: Expected an expression [case testIgnoreAppliesOnlyToMissing] import a # type: ignore @@ -54,12 +54,12 @@ foo = 3 [builtins fixtures/module_all.pyi] [out] -[case testIgnoreImportStarFromBadModule_no_native_parse] +[case testIgnoreImportStarFromBadModule] from m import * # type: ignore [file m.py] + [out] -tmp/m.py:1: error: Invalid syntax +tmp/m.py:1: error: Expected an expression [case testIgnoreAssignmentTypeError] x = 1 diff --git a/test-data/unit/check-incremental.test b/test-data/unit/check-incremental.test index 18931dd9f152f..22e6b99439d2c 100644 --- a/test-data/unit/check-incremental.test +++ b/test-data/unit/check-incremental.test @@ -7260,7 +7260,7 @@ bar: int = foo [out3] tmp/bar.py:2: error: Incompatible types in assignment (expression has type "str", variable has type "int") -[case testIncrementalBlockingErrorRepeatAndUndo_no_native_parse] +[case testIncrementalBlockingErrorRepeatAndUndo] import m [file m.py] import f @@ -7278,9 +7278,9 @@ x = 1 [out] tmp/m.py:2: note: Revealed type is "builtins.int" [out2] -tmp/f.py:1: error: Invalid syntax +tmp/f.py:1: error: Simple statements must be separated by newlines or semicolons [out3] -tmp/f.py:1: error: Invalid syntax +tmp/f.py:1: error: Simple statements must be separated by newlines or semicolons [out4] tmp/m.py:2: note: Revealed type is "builtins.int" diff --git a/test-data/unit/check-literal.test b/test-data/unit/check-literal.test index f795f1f5b354b..bbd9f37783029 100644 --- a/test-data/unit/check-literal.test +++ b/test-data/unit/check-literal.test @@ -224,7 +224,7 @@ accepts_bytes(c_alias) [builtins fixtures/tuple.pyi] [out] -[case testLiteralMixingUnicodeAndBytesPython3ForwardStrings_no_native_parse] +[case testLiteralMixingUnicodeAndBytesPython3ForwardStrings] from typing import Literal, TypeVar, Generic a_unicode_wrapper: u"Literal[u'foo']" @@ -577,8 +577,7 @@ reveal_type(d) # N: Revealed type is "Any" [builtins fixtures/primitives.pyi] [out] -[case testLiteralDisallowFloatsAndComplex_no_native_parse] - +[case testLiteralDisallowFloatsAndComplex] from typing import Literal a1: Literal[3.14] # E: Parameter 1 of Literal[...] cannot be of type "float" b1: 3.14 # E: Invalid type: float literals cannot be used as a type @@ -601,7 +600,7 @@ d2: d2t # E: Variable "__main__.d2t" is not valid as a type \ [builtins fixtures/complex_tuple.pyi] [out] -[case testLiteralDisallowComplexExpressions_no_native_parse] +[case testLiteralDisallowComplexExpressions] from typing import Literal def dummy() -> int: return 3 a: Literal[3 + 4] # E: Invalid type: Literal[...] cannot contain arbitrary expressions @@ -2460,7 +2459,7 @@ expect_2(final_set_2.pop()) # E: Argument 1 to "expect_2" has incompatible type -- Tests for Literals and enums -- -[case testLiteralWithEnumsBasic_no_native_parse] +[case testLiteralWithEnumsBasic] from typing import Literal from enum import Enum diff --git a/test-data/unit/check-namedtuple.test b/test-data/unit/check-namedtuple.test index 158b95aa598d0..1ed57c72fcd23 100644 --- a/test-data/unit/check-namedtuple.test +++ b/test-data/unit/check-namedtuple.test @@ -1362,7 +1362,7 @@ class Test: [builtins fixtures/tuple.pyi] [typing fixtures/typing-namedtuple.pyi] -[case testNoClassKeywordsForNamedTuple_no_native_parse] +[case testNoClassKeywordsForNamedTuple] from typing import NamedTuple class Test1(NamedTuple, x=1, y=2): # E: Unexpected keyword argument "x" for "__init_subclass__" of "NamedTuple" \ # E: Unexpected keyword argument "y" for "__init_subclass__" of "NamedTuple" diff --git a/test-data/unit/check-newsemanal.test b/test-data/unit/check-newsemanal.test index cfb59a9f8e9ba..db224628546ad 100644 --- a/test-data/unit/check-newsemanal.test +++ b/test-data/unit/check-newsemanal.test @@ -1652,7 +1652,7 @@ tmp/a.py: note: In member "g" of class "A": tmp/a.py:10: error: Type argument "str" of "C" must be a subtype of "int" tmp/a.py:11: error: Type argument "str" of "C" must be a subtype of "int" -[case testNewAnalyzerTypeArgBoundCheckDifferentNodes_no_native_parse] +[case testNewAnalyzerTypeArgBoundCheckDifferentNodes] from typing import TypeVar, TypedDict, Generic, NamedTuple, NewType, Union, Any, cast, overload T = TypeVar('T', bound=int) diff --git a/test-data/unit/check-newsyntax.test b/test-data/unit/check-newsyntax.test index 3df0d03c96e10..7f70c9de0aaf3 100644 --- a/test-data/unit/check-newsyntax.test +++ b/test-data/unit/check-newsyntax.test @@ -1,5 +1,5 @@ -[case testNewSyntaxSyntaxError_no_native_parse] -x: int: int # E: Invalid syntax +[case testNewSyntaxSyntaxError] +x: int: int # E: Expected a statement [out] [case testNewSyntaxBasics] @@ -122,7 +122,8 @@ reveal_type(f'{v}') # N: Revealed type is "builtins.str" reveal_type(f'{1}') # N: Revealed type is "builtins.str" [builtins fixtures/f_string.pyi] -[case testFeatureVersionSuggestion_no_native_parse] +-- Native parser can parse future versions of Python +[case testFeatureVersionSuggestion_old_parser] # flags: --python-version 3.99 x *** x this is what future python looks like public static void main String[] args await goto exit [out] diff --git a/test-data/unit/check-overloading.test b/test-data/unit/check-overloading.test index 721ca52f59eed..e92f3cd8a53a0 100644 --- a/test-data/unit/check-overloading.test +++ b/test-data/unit/check-overloading.test @@ -6156,7 +6156,7 @@ reveal_type(f3(A())) # E: No overload variant of "f3" matches argument type "A" # N: Revealed type is "Any" reveal_type(f3(B())) # N: Revealed type is "__main__.B" -[case testOverloadIfSplitFunctionDef_no_native_parse] +[case testOverloadIfSplitFunctionDef] # flags: --always-true True --always-false False from typing import overload diff --git a/test-data/unit/check-python312.test b/test-data/unit/check-python312.test index 9d612109d5452..dc97803477214 100644 --- a/test-data/unit/check-python312.test +++ b/test-data/unit/check-python312.test @@ -1641,7 +1641,7 @@ reveal_type(a) # N: Revealed type is "builtins.list[builtins.int]" def f[T](x: foobar, y: T) -> T: ... # E: Name "foobar" is not defined reveal_type(f) # N: Revealed type is "def [T] (x: Any, y: T`-1) -> T`-1" -[case testPEP695WrongNumberOfConstrainedTypes_no_native_parse] +[case testPEP695WrongNumberOfConstrainedTypes] type A[T: ()] = list[T] # E: Type variable must have at least two constrained types a: A[int] reveal_type(a) # N: Revealed type is "builtins.list[builtins.int]" @@ -1790,7 +1790,7 @@ type Y[T] = {"item": T, **Y[T]} # E: Overwriting TypedDict field "item" while m [builtins fixtures/dict.pyi] [typing fixtures/typing-full.pyi] -[case testPEP695UsingIncorrectExpressionsInTypeVariableBound_no_native_parse] +[case testPEP695UsingIncorrectExpressionsInTypeVariableBound] type X[T: (yield 1)] = Any # E: Yield expression cannot be used as a type variable bound type Y[T: (yield from [])] = Any # E: Yield expression cannot be used as a type variable bound type Z[T: (a := 1)] = Any # E: Named expression cannot be used as a type variable bound @@ -1821,7 +1821,7 @@ def fooy_nested[T: (1 + (yield from []))](): pass # E: Yield expression cannot def fooz_nested[T: (1 + (a := 1))](): pass # E: Named expression cannot be used as a type variable bound def fook_nested[T: (1 +(await 1))](): pass # E: Await expression cannot be used as a type variable bound -[case testPEP695UsingIncorrectExpressionsInTypeAlias_no_native_parse] +[case testPEP695UsingIncorrectExpressionsInTypeAlias] type X = (yield 1) # E: Yield expression cannot be used within a type alias type Y = (yield from []) # E: Yield expression cannot be used within a type alias type Z = (a := 1) # E: Named expression cannot be used within a type alias diff --git a/test-data/unit/check-python39.test b/test-data/unit/check-python39.test index 1e96fe67ffcd0..e255a9085a2a1 100644 --- a/test-data/unit/check-python39.test +++ b/test-data/unit/check-python39.test @@ -1,10 +1,10 @@ -[case testGivingSameKeywordArgumentTwice_no_native_parse] +[case testGivingSameKeywordArgumentTwice] # This test was originally in check-kwargs.test import typing def f(a: 'A', b: 'B') -> None: pass class A: pass class B: pass -f(a=A(), b=B(), a=A()) # E: "f" gets multiple values for keyword argument "a" +f(a=A(), b=B(), a=A()) # E: Duplicate keyword argument "a" [case testPEP614] diff --git a/test-data/unit/check-statements.test b/test-data/unit/check-statements.test index cb445cf4a1a2b..1db257b06e9ad 100644 --- a/test-data/unit/check-statements.test +++ b/test-data/unit/check-statements.test @@ -164,8 +164,7 @@ while None: [builtins fixtures/bool.pyi] [out] -[case testForStatementTypeComments_no_native_parse] - +[case testForStatementTypeComments_old_parser] from typing import List, Union x = [] # type: List[int] @@ -182,8 +181,7 @@ for v in x: # type: int, int # E: Syntax error in type annotation # N: Suggest pass [builtins fixtures/list.pyi] -[case testForStatementMultipleTypeComments_no_native_parse] - +[case testForStatementMultipleTypeComments_old_parser] from typing import List, Tuple x = [] # type: List[Tuple[int, int]] @@ -1391,9 +1389,9 @@ def f() -> Iterator[List[int]]: [builtins fixtures/for.pyi] [out] -[case testYieldFromNotAppliedToNothing_no_native_parse] +[case testYieldFromNotAppliedToNothing] def h(): - yield from # E: Invalid syntax + yield from # E: Expected an expression [out] [case testYieldFromAndYieldTogether] @@ -1523,8 +1521,7 @@ with A() as (a, b): a = b # E: Incompatible types in assignment (expression has type "str", variable has type "int") [builtins fixtures/tuple.pyi] -[case testWithStmtTypeComment_no_native_parse] - +[case testWithStmtTypeComment_old_parser] from typing import Union class A: def __enter__(self) -> int: pass @@ -1545,8 +1542,7 @@ with A() as c: # type: int, int # E: Syntax error in type annotation # N: Sugg with A() as d: # type: Union[int, str] reveal_type(d) # N: Revealed type is "builtins.int | builtins.str" -[case testWithStmtTupleTypeComment_no_native_parse] - +[case testWithStmtTupleTypeComment_old_parser] from typing import Tuple class A: def __enter__(self) -> Tuple[int, int]: pass @@ -1577,8 +1573,7 @@ with A() as (k, l): # type: int, str # E: Incompatible types in assignment (ex pass [builtins fixtures/tuple.pyi] -[case testWithStmtComplexTypeComment_no_native_parse] - +[case testWithStmtComplexTypeComment_old_parser] from typing import Tuple class A: def __enter__(self) -> Tuple[int, int]: pass @@ -2275,7 +2270,7 @@ N = TypedDict('N', {'x': int}) [typing fixtures/typing-full.pyi] [out] -[case testForwardRefsInWithStatement_no_native_parse] +[case testForwardRefsInWithStatement_old_parser] from typing import ContextManager, Any, TypedDict cm: ContextManager[Any] diff --git a/test-data/unit/check-type-aliases.test b/test-data/unit/check-type-aliases.test index e48700c69e38e..3f712eae7c54d 100644 --- a/test-data/unit/check-type-aliases.test +++ b/test-data/unit/check-type-aliases.test @@ -1164,7 +1164,7 @@ reveal_type(xp) # N: Revealed type is "__main__.G[[builtins.int], builtins.str] [builtins fixtures/dict.pyi] [typing fixtures/typing-full.pyi] -[case testTypeAliasTypeInvalidGeneric_no_native_parse] +[case testTypeAliasTypeInvalidGeneric] from typing_extensions import TypeAliasType, TypeVarTuple, ParamSpec from typing import Callable, Dict, Generic, TypeVar, Tuple, Unpack @@ -1199,9 +1199,9 @@ reveal_type(unbound_tvt_alias) # N: Revealed type is "builtins.tuple[Any, ...]" class G(Generic[P, T]): ... Ta7 = TypeAliasType("Ta7", G[P, T]) # E: ParamSpec "P" is not included in type_params \ # E: Type variable "T" is not included in type_params -unbound_ps_alias: Ta7[[int], str] # E: Bracketed expression "[...]" is not valid as a type \ - # N: Did you mean "List[...]"? \ - # E: Bad number of arguments for type alias, expected 0, given 2 +unbound_ps_alias: Ta7[[int], str] # E: Bad number of arguments for type alias, expected 0, given 2 \ + # E: Bracketed expression "[...]" is not valid as a type \ + # N: Did you mean "List[...]"? reveal_type(unbound_ps_alias) # N: Revealed type is "__main__.G[Any, Any]" Ta8 = TypeAliasType("Ta8", Callable[P, int]) # E: ParamSpec "P" is not included in type_params diff --git a/test-data/unit/check-typeddict.test b/test-data/unit/check-typeddict.test index 01414ee2f457a..7013bc5859f9f 100644 --- a/test-data/unit/check-typeddict.test +++ b/test-data/unit/check-typeddict.test @@ -4116,7 +4116,7 @@ B = TypedDict("B", { # E: Type of a TypedDict key becomes "Any" due to an unfol [builtins fixtures/dict.pyi] [typing fixtures/typing-typeddict.pyi] -[case testTypedDictWithClassLevelKeywords_no_native_parse] +[case testTypedDictWithClassLevelKeywords] from typing import TypedDict, Generic, TypeVar T = TypeVar('T') @@ -5253,10 +5253,10 @@ reveal_type(c) # N: Revealed type is "TypedDict('__main__.C', {'x': builtins.int [builtins fixtures/dict.pyi] [typing fixtures/typing-typeddict.pyi] -[case testTypedDictWithDuplicateKeywordArguments_no_parallel] +[case testTypedDictWithDuplicateKeywordArguments] from typing import TypedDict -A = TypedDict('A', {'x': int}, closed=True, closed=False) # E: Repeated keyword argument "closed" for "TypedDict" -B = TypedDict('B', {'x': int}, total=True, total=False) # E: Repeated keyword argument "total" for "TypedDict" +A = TypedDict('A', {'x': int}, closed=True, closed=False) # E: Duplicate keyword argument "closed" +B = TypedDict('B', {'x': int}, total=True, total=False) # E: Duplicate keyword argument "total" [builtins fixtures/dict.pyi] [typing fixtures/typing-typeddict.pyi] diff --git a/test-data/unit/check-unreachable-code.test b/test-data/unit/check-unreachable-code.test index 330983dab6203..89e147af1253c 100644 --- a/test-data/unit/check-unreachable-code.test +++ b/test-data/unit/check-unreachable-code.test @@ -452,7 +452,7 @@ reveal_type(x) # N: Revealed type is "builtins.str" [builtins fixtures/ops.pyi] [out] -[case testCustomSysPlatform2_no_native_parse] +[case testCustomSysPlatform2] # flags: --platform win32 import sys if sys.platform == 'linux': @@ -463,7 +463,7 @@ reveal_type(x) # N: Revealed type is "builtins.int" [builtins fixtures/ops.pyi] [out] -[case testCustomSysPlatformStartsWith_no_native_parse] +[case testCustomSysPlatformStartsWith] # flags: --platform win32 import sys if sys.platform.startswith('win'): @@ -887,7 +887,7 @@ def baz(x: int) -> int: return x [builtins fixtures/exception.pyi] -[case testUnreachableFlagIgnoresSemanticAnalysisUnreachable_no_native_parse] +[case testUnreachableFlagIgnoresSemanticAnalysisUnreachable] # flags: --warn-unreachable --python-version 3.10 --platform win32 --always-false FOOBAR import sys from typing import TYPE_CHECKING diff --git a/test-data/unit/deps-statements.test b/test-data/unit/deps-statements.test index a67f9c762009d..72c2e75ff5335 100644 --- a/test-data/unit/deps-statements.test +++ b/test-data/unit/deps-statements.test @@ -207,7 +207,7 @@ def g() -> None: -> , m.A.__enter__, m.C -> , m.B.__enter__, m.D -[case testWithStmtAnnotation] +[case testWithStmtAnnotation_old_parser] from typing import Any class A: def __enter__(self) -> Any: pass @@ -228,7 +228,7 @@ def g() -> None: -> , m.B, m.f, m.g -> m.g -[case testForStmtAnnotation] +[case testForStmtAnnotation_old_parser] class A: def __iter__(self): pass diff --git a/test-data/unit/fine-grained.test b/test-data/unit/fine-grained.test index ef2e8c0b343bf..a6df9c864dcde 100644 --- a/test-data/unit/fine-grained.test +++ b/test-data/unit/fine-grained.test @@ -8226,7 +8226,7 @@ a.py:10: error: Name "bar" already defined on line 6 a.py:11: error: Variable "a.T" is not valid as a type a.py:11: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases -[case testRefreshForWithTypeComment1] +[case testRefreshForWithTypeComment1_old_parser] [file a.py] from typing import List import b @@ -8243,7 +8243,7 @@ x = '1' [out] == -[case testRefreshForWithTypeComment2] +[case testRefreshForWithTypeComment2_old_parser] from typing import List, Any import m def f(x: List[Any]) -> None: diff --git a/test-data/unit/semanal-classvar.test b/test-data/unit/semanal-classvar.test index 62151666c011a..89d990eb144db 100644 --- a/test-data/unit/semanal-classvar.test +++ b/test-data/unit/semanal-classvar.test @@ -176,14 +176,14 @@ class A: [out] main:4: error: ClassVar can only be used for assignments in class body -[case testForIndex] +[case testForIndex_old_parser] from typing import ClassVar for i in []: # type: ClassVar pass [out] main:2: error: ClassVar can only be used for assignments in class body -[case testForIndexInClassBody] +[case testForIndexInClassBody_old_parser] from typing import ClassVar class A: for i in []: # type: ClassVar @@ -191,7 +191,7 @@ class A: [out] main:3: error: ClassVar can only be used for assignments in class body -[case testWithStmt] +[case testWithStmt_old_parser] from typing import ClassVar class A: pass with A() as x: # type: ClassVar @@ -199,7 +199,7 @@ with A() as x: # type: ClassVar [out] main:3: error: ClassVar can only be used for assignments in class body -[case testWithStmtInClassBody] +[case testWithStmtInClassBody_old_parser] from typing import ClassVar class A: pass class B: