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/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/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-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: 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