From e7216905472aeed32ac6322fff7a9e51d116db6b Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Wed, 15 Dec 2021 18:36:28 +0100 Subject: [PATCH 1/2] Fix tests for Python 3.10.1 (2) https://bugs.python.org/issue46004 --- test-data/unit/fine-grained-blockers.test | 58 +++++++++++++++++++++++ test-data/unit/parse.test | 4 ++ 2 files changed, 62 insertions(+) diff --git a/test-data/unit/fine-grained-blockers.test b/test-data/unit/fine-grained-blockers.test index 17a5c42c1128..01e33834c566 100644 --- a/test-data/unit/fine-grained-blockers.test +++ b/test-data/unit/fine-grained-blockers.test @@ -161,6 +161,11 @@ main:5: error: Missing positional argument "x" in call to "f" of "C" a.py:1: error: invalid syntax. Perhaps you forgot a comma? == main:5: error: Missing positional argument "x" in call to "f" of "C" +[out version>=3.10.1] +== +a.py:1: error: invalid syntax +== +main:5: error: Missing positional argument "x" in call to "f" of "C" [case testAddFileWithBlockingError] import a @@ -183,6 +188,13 @@ main:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missin a.py:1: error: invalid syntax. Perhaps you forgot a comma? == main:2: error: Too many arguments for "f" +[out version>=3.10.1] +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 +== +main:2: error: Too many arguments for "f" [case testModifyTwoFilesOneWithBlockingError1] import a @@ -266,6 +278,13 @@ a.py:1: error: invalid syntax. Perhaps you forgot a comma? a.py:1: error: invalid syntax. Perhaps you forgot a comma? == a.py:2: error: Missing positional argument "x" in call to "f" +[out version>=3.10.1] +== +a.py:1: error: invalid syntax +== +a.py:1: error: invalid syntax +== +a.py:2: error: Missing positional argument "x" in call to "f" [case testModifyTwoFilesIntroduceTwoBlockingErrors] import a @@ -337,6 +356,13 @@ a.py:1: error: invalid syntax. Perhaps you forgot a comma? 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.1] +== +a.py:1: error: invalid syntax +== +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" [case testDeleteFileWithBlockingError2-only_when_cache] -- Different cache/no-cache tests because: @@ -365,6 +391,13 @@ a.py:1: error: invalid syntax. Perhaps you forgot a comma? 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.1] +== +a.py:1: error: invalid syntax +== +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" [case testModifyFileWhileBlockingErrorElsewhere] import a @@ -396,6 +429,14 @@ a.py:1: error: invalid syntax. Perhaps you forgot a comma? == b.py:2: error: Module has no attribute "f" b.py:3: error: "int" not callable +[out version>=3.10.1] +== +a.py:1: error: invalid syntax +== +a.py:1: error: invalid syntax +== +b.py:2: error: Module has no attribute "f" +b.py:3: error: "int" not callable [case testImportBringsAnotherFileWithBlockingError1] import a @@ -416,6 +457,11 @@ a.py:1: error: "int" not callable /test-data/unit/lib-stub/blocker.pyi:2: error: invalid syntax. Perhaps you forgot a comma? == a.py:1: error: "int" not callable +[out version>=3.10.1] +== +/test-data/unit/lib-stub/blocker.pyi:2: error: invalid syntax +== +a.py:1: error: "int" not callable [case testImportBringsAnotherFileWithSemanticAnalysisBlockingError] import a @@ -497,6 +543,13 @@ a.py:1: error: invalid syntax. Perhaps you forgot a comma? /test-data/unit/lib-stub/blocker.pyi:2: error: invalid syntax. Perhaps you forgot a comma? == a.py:2: error: "int" not callable +[out version>=3.10.1] +== +a.py:1: error: invalid syntax +== +/test-data/unit/lib-stub/blocker.pyi:2: error: invalid syntax +== +a.py:2: error: "int" not callable [case testInitialBlocker] # cmd: mypy a.py b.py @@ -520,6 +573,11 @@ a.py:1: error: invalid syntax. Perhaps you forgot a comma? == b.py:2: error: Incompatible return value type (got "str", expected "int") == +[out version>=3.10.1] +a.py:1: error: invalid syntax +== +b.py:2: error: Incompatible return value type (got "str", expected "int") +== [case testDecodeErrorBlocker1-posix] import a diff --git a/test-data/unit/parse.test b/test-data/unit/parse.test index 7f3694120b12..4cb1d5591d16 100644 --- a/test-data/unit/parse.test +++ b/test-data/unit/parse.test @@ -937,6 +937,8 @@ x not y main:1: error: invalid syntax [out version>=3.10] main:1: error: invalid syntax. Perhaps you forgot a comma? +[out version>=3.10.1] +main:1: error: invalid syntax [case testNotIs] x not is y # E: invalid syntax @@ -948,6 +950,8 @@ x not is y # E: invalid syntax main:1: error: invalid syntax [out version>=3.10] main:1: error: invalid syntax. Perhaps you forgot a comma? +[out version>=3.10.1] +main:1: error: invalid syntax [case testSliceInList39] # flags: --python-version 3.9 From e71ab39cf0847f233c4797e4c9f58b0a83ffa7f4 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Wed, 15 Dec 2021 22:36:16 +0100 Subject: [PATCH 2/2] Add support for version equals test output --- mypy/test/data.py | 20 ++++-- test-data/unit/check-errorcodes.test | 4 +- test-data/unit/fine-grained-blockers.test | 76 +++-------------------- test-data/unit/parse.test | 8 +-- 4 files changed, 27 insertions(+), 81 deletions(-) diff --git a/mypy/test/data.py b/mypy/test/data.py index 17cda87c1bd3..e886b11ffa8e 100644 --- a/mypy/test/data.py +++ b/mypy/test/data.py @@ -114,9 +114,11 @@ def parse_test_case(case: 'DataDrivenTestCase') -> None: if arg == 'skip-path-normalization': normalize_output = False if arg.startswith("version"): - if arg[7:9] != ">=": + compare_op = arg[7:9] + if compare_op not in {">=", "=="}: raise ValueError( - "{}, line {}: Only >= version checks are currently supported".format( + "{}, line {}: Only >= and == version checks are currently supported" + .format( case.file, item.line ) ) @@ -127,9 +129,17 @@ def parse_test_case(case: 'DataDrivenTestCase') -> None: raise ValueError( '{}, line {}: "{}" is not a valid python version'.format( case.file, item.line, version_str)) - if not sys.version_info >= version: - version_check = False - + if compare_op == ">=": + version_check = sys.version_info >= version + elif compare_op == "==": + if not 1 < len(version) < 4: + raise ValueError( + '{}, line {}: Only minor or patch version checks ' + 'are currently supported with "==": "{}"'.format( + case.file, item.line, version_str + ) + ) + version_check = sys.version_info[:len(version)] == version if version_check: tmp_output = [expand_variables(line) for line in item.data] if os.path.sep == '\\' and normalize_output: diff --git a/test-data/unit/check-errorcodes.test b/test-data/unit/check-errorcodes.test index 1ceafaed8dff..2f84ee1f4c6e 100644 --- a/test-data/unit/check-errorcodes.test +++ b/test-data/unit/check-errorcodes.test @@ -34,10 +34,8 @@ reveal_type(1) # N: Revealed type is "Literal[1]?" 1 '' [out] main:1: error: invalid syntax [syntax] -[out version>=3.10] +[out version==3.10.0] main:1: error: invalid syntax. Perhaps you forgot a comma? [syntax] -[out version>=3.10.1] -main:1: error: invalid syntax [syntax] [case testErrorCodeSyntaxError2] def f(): # E: Type signature has too many arguments [syntax] diff --git a/test-data/unit/fine-grained-blockers.test b/test-data/unit/fine-grained-blockers.test index 01e33834c566..66a68115afa5 100644 --- a/test-data/unit/fine-grained-blockers.test +++ b/test-data/unit/fine-grained-blockers.test @@ -156,16 +156,11 @@ class C: a.py:1: error: invalid syntax == main:5: error: Missing positional argument "x" in call to "f" of "C" -[out version>=3.10] +[out version==3.10.0] == a.py:1: error: invalid syntax. Perhaps you forgot a comma? == main:5: error: Missing positional argument "x" in call to "f" of "C" -[out version>=3.10.1] -== -a.py:1: error: invalid syntax -== -main:5: error: Missing positional argument "x" in call to "f" of "C" [case testAddFileWithBlockingError] import a @@ -181,20 +176,13 @@ main:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missin a.py:1: error: invalid syntax == main:2: error: Too many arguments for "f" -[out version>=3.10] +[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? == main:2: error: Too many arguments for "f" -[out version>=3.10.1] -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 -== -main:2: error: Too many arguments for "f" [case testModifyTwoFilesOneWithBlockingError1] import a @@ -271,20 +259,13 @@ a.py:1: error: invalid syntax a.py:1: error: invalid syntax == a.py:2: error: Missing positional argument "x" in call to "f" -[out version>=3.10] +[out version==3.10.0] == a.py:1: error: invalid syntax. Perhaps you forgot a comma? == a.py:1: error: invalid syntax. Perhaps you forgot a comma? == a.py:2: error: Missing positional argument "x" in call to "f" -[out version>=3.10.1] -== -a.py:1: error: invalid syntax -== -a.py:1: error: invalid syntax -== -a.py:2: error: Missing positional argument "x" in call to "f" [case testModifyTwoFilesIntroduceTwoBlockingErrors] import a @@ -349,20 +330,13 @@ a.py:1: error: invalid syntax 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] +[out version==3.10.0] == a.py:1: error: invalid syntax. Perhaps you forgot a comma? == 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.1] -== -a.py:1: error: invalid syntax -== -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" [case testDeleteFileWithBlockingError2-only_when_cache] -- Different cache/no-cache tests because: @@ -384,20 +358,13 @@ a.py:1: error: invalid syntax 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] +[out version==3.10.0] == a.py:1: error: invalid syntax. Perhaps you forgot a comma? == 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.1] -== -a.py:1: error: invalid syntax -== -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" [case testModifyFileWhileBlockingErrorElsewhere] import a @@ -421,7 +388,7 @@ a.py:1: error: invalid syntax == b.py:2: error: Module has no attribute "f" b.py:3: error: "int" not callable -[out version>=3.10] +[out version==3.10.0] == a.py:1: error: invalid syntax. Perhaps you forgot a comma? == @@ -429,14 +396,6 @@ a.py:1: error: invalid syntax. Perhaps you forgot a comma? == b.py:2: error: Module has no attribute "f" b.py:3: error: "int" not callable -[out version>=3.10.1] -== -a.py:1: error: invalid syntax -== -a.py:1: error: invalid syntax -== -b.py:2: error: Module has no attribute "f" -b.py:3: error: "int" not callable [case testImportBringsAnotherFileWithBlockingError1] import a @@ -452,16 +411,11 @@ def f() -> None: pass /test-data/unit/lib-stub/blocker.pyi:2: error: invalid syntax == a.py:1: error: "int" not callable -[out version>=3.10] +[out version==3.10.0] == /test-data/unit/lib-stub/blocker.pyi:2: error: invalid syntax. Perhaps you forgot a comma? == a.py:1: error: "int" not callable -[out version>=3.10.1] -== -/test-data/unit/lib-stub/blocker.pyi:2: error: invalid syntax -== -a.py:1: error: "int" not callable [case testImportBringsAnotherFileWithSemanticAnalysisBlockingError] import a @@ -536,20 +490,13 @@ a.py:1: error: invalid syntax /test-data/unit/lib-stub/blocker.pyi:2: error: invalid syntax == a.py:2: error: "int" not callable -[out version>=3.10] +[out version==3.10.0] == a.py:1: error: invalid syntax. Perhaps you forgot a comma? == /test-data/unit/lib-stub/blocker.pyi:2: error: invalid syntax. Perhaps you forgot a comma? == a.py:2: error: "int" not callable -[out version>=3.10.1] -== -a.py:1: error: invalid syntax -== -/test-data/unit/lib-stub/blocker.pyi:2: error: invalid syntax -== -a.py:2: error: "int" not callable [case testInitialBlocker] # cmd: mypy a.py b.py @@ -568,16 +515,11 @@ a.py:1: error: invalid syntax == b.py:2: error: Incompatible return value type (got "str", expected "int") == -[out version>=3.10] +[out version==3.10.0] a.py:1: error: invalid syntax. Perhaps you forgot a comma? == b.py:2: error: Incompatible return value type (got "str", expected "int") == -[out version>=3.10.1] -a.py:1: error: invalid syntax -== -b.py:2: error: Incompatible return value type (got "str", expected "int") -== [case testDecodeErrorBlocker1-posix] import a diff --git a/test-data/unit/parse.test b/test-data/unit/parse.test index 4cb1d5591d16..ff892ce0ce05 100644 --- a/test-data/unit/parse.test +++ b/test-data/unit/parse.test @@ -935,10 +935,8 @@ MypyFile:1( x not y [out] main:1: error: invalid syntax -[out version>=3.10] +[out version==3.10.0] main:1: error: invalid syntax. Perhaps you forgot a comma? -[out version>=3.10.1] -main:1: error: invalid syntax [case testNotIs] x not is y # E: invalid syntax @@ -948,10 +946,8 @@ x not is y # E: invalid syntax 1 ~ 2 [out] main:1: error: invalid syntax -[out version>=3.10] +[out version==3.10.0] main:1: error: invalid syntax. Perhaps you forgot a comma? -[out version>=3.10.1] -main:1: error: invalid syntax [case testSliceInList39] # flags: --python-version 3.9