Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a bunch of tests broken by python 3.10 #10404

Merged
merged 1 commit into from
May 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 36 additions & 12 deletions mypy/test/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,43 @@ def parse_test_case(case: 'DataDrivenTestCase') -> None:
full = join(base_path, m.group(1))
deleted_paths.setdefault(num, set()).add(full)
elif re.match(r'out[0-9]*$', item.id):
if item.arg == 'skip-path-normalization':
normalize_output = False

tmp_output = [expand_variables(line) for line in item.data]
if os.path.sep == '\\' and normalize_output:
tmp_output = [fix_win_path(line) for line in tmp_output]
if item.id == 'out' or item.id == 'out1':
output = tmp_output
if item.arg is None:
args = []
else:
passnum = int(item.id[len('out'):])
assert passnum > 1
output2[passnum] = tmp_output
out_section_missing = False
args = item.arg.split(",")

version_check = True
for arg in args:
if arg == 'skip-path-normalization':
normalize_output = False
if arg.startswith("version"):
if arg[7:9] != ">=":
raise ValueError(
"{}, line {}: Only >= version checks are currently supported".format(
case.file, item.line
)
)
version_str = arg[9:]
try:
version = tuple(int(x) for x in version_str.split("."))
except ValueError:
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 version_check:
tmp_output = [expand_variables(line) for line in item.data]
if os.path.sep == '\\' and normalize_output:
tmp_output = [fix_win_path(line) for line in tmp_output]
if item.id == 'out' or item.id == 'out1':
output = tmp_output
else:
passnum = int(item.id[len('out'):])
assert passnum > 1
output2[passnum] = tmp_output
out_section_missing = False
elif item.id == 'triggered' and item.arg is None:
triggered = item.data
else:
Expand Down
6 changes: 5 additions & 1 deletion test-data/unit/check-errorcodes.test
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ class A:
reveal_type(1) # N: Revealed type is "Literal[1]?"

[case testErrorCodeSyntaxError]
1 '' # E: invalid syntax [syntax]
1 ''
[out]
main:1: error: invalid syntax [syntax]
[out version>=3.10]
main:1: error: invalid syntax. Perhaps you forgot a comma? [syntax]

[case testErrorCodeSyntaxError2]
def f(): # E: Type signature has too many arguments [syntax]
Expand Down
7 changes: 7 additions & 0 deletions test-data/unit/cmdline.test
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,9 @@ def foo(
[out]
a.py:1: error: unexpected EOF while parsing
== Return code: 2
[out version>=3.10]
a.py:1: error: '(' was never closed
== Return code: 2

[case testParseErrorAnnots]
# cmd: mypy a.py
Expand Down Expand Up @@ -1236,6 +1239,10 @@ x: str = 0
pkg/x.py:1: error: invalid syntax
Found 1 error in 1 file (errors prevented further checking)
== Return code: 2
[out version>=3.10]
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

[case testCmdlinePackageAndFile]
# cmd: mypy -p pkg file
Expand Down
89 changes: 89 additions & 0 deletions test-data/unit/fine-grained-blockers.test
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ a.py:1: error: invalid syntax
==
main:2: error: Missing positional argument "x" in call to "f"
==
[out version>=3.10]
==
a.py:1: error: expected ':'
==
main:2: error: Missing positional argument "x" in call to "f"
==

[case testParseErrorShowSource]
# flags: --pretty --show-error-codes
Expand All @@ -46,6 +52,16 @@ main:3: error: Missing positional argument "x" in call to "f" [call-arg]
a.f()
^
==
[out version>=3.10]
==
a.py:1: error: expected ':' [syntax]
def f(x: int) ->
^
==
main:3: error: Missing positional argument "x" in call to "f" [call-arg]
a.f()
^
==

[case testParseErrorMultipleTimes]
import a
Expand All @@ -66,6 +82,13 @@ a.py:1: error: invalid syntax
a.py:2: error: invalid syntax
==
main:2: error: Missing positional argument "x" in call to "f"
[out version>=3.10]
==
a.py:1: error: expected ':'
==
a.py:2: error: expected ':'
==
main:2: error: Missing positional argument "x" in call to "f"

[case testSemanticAnalysisBlockingError]
import a
Expand Down Expand Up @@ -105,6 +128,14 @@ a.py:1: error: invalid syntax
==
main:3: error: Too many arguments for "f"
main:5: error: Too many arguments for "f"
[out version>=3.10]
main:3: error: Too many arguments for "f"
main:5: error: Too many arguments for "f"
==
a.py:1: error: expected ':'
==
main:3: error: Too many arguments for "f"
main:5: error: Too many arguments for "f"

[case testUpdateClassReferenceAcrossBlockingError]
import a
Expand All @@ -125,6 +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]
==
a.py:1: error: invalid syntax. Perhaps you forgot a comma?
==
main:5: error: Missing positional argument "x" in call to "f" of "C"

[case testAddFileWithBlockingError]
import a
Expand All @@ -140,6 +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]
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"

[case testModifyTwoFilesOneWithBlockingError1]
import a
Expand Down Expand Up @@ -216,6 +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]
==
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"

[case testModifyTwoFilesIntroduceTwoBlockingErrors]
import a
Expand Down Expand Up @@ -280,6 +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]
==
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"

[case testDeleteFileWithBlockingError-only_when_cache]
-- Different cache/no-cache tests because:
Expand All @@ -301,6 +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]
==
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"

[case testModifyFileWhileBlockingErrorElsewhere]
import a
Expand All @@ -324,6 +388,14 @@ 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]
==
a.py:1: error: invalid syntax. Perhaps you forgot a comma?
==
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

[case testImportBringsAnotherFileWithBlockingError1]
import a
Expand All @@ -339,6 +411,11 @@ def f() -> None: pass
<ROOT>/test-data/unit/lib-stub/blocker.pyi:2: error: invalid syntax
==
a.py:1: error: "int" not callable
[out version>=3.10]
==
<ROOT>/test-data/unit/lib-stub/blocker.pyi:2: error: invalid syntax. Perhaps you forgot a comma?
==
a.py:1: error: "int" not callable

[case testImportBringsAnotherFileWithSemanticAnalysisBlockingError]
import a
Expand Down Expand Up @@ -413,6 +490,13 @@ a.py:1: error: invalid syntax
<ROOT>/test-data/unit/lib-stub/blocker.pyi:2: error: invalid syntax
==
a.py:2: error: "int" not callable
[out version>=3.10]
==
a.py:1: error: invalid syntax. Perhaps you forgot a comma?
==
<ROOT>/test-data/unit/lib-stub/blocker.pyi:2: error: invalid syntax. Perhaps you forgot a comma?
==
a.py:2: error: "int" not callable

[case testInitialBlocker]
# cmd: mypy a.py b.py
Expand All @@ -431,6 +515,11 @@ a.py:1: error: invalid syntax
==
b.py:2: error: Incompatible return value type (got "str", expected "int")
==
[out version>=3.10]
a.py:1: error: invalid syntax. Perhaps you forgot a comma?
==
b.py:2: error: Incompatible return value type (got "str", expected "int")
==

[case testDecodeErrorBlocker-posix]
import a
Expand Down
5 changes: 5 additions & 0 deletions test-data/unit/fine-grained-suggest.test
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,11 @@ 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: unexpected EOF while parsing
[out version>=3.10]
foo.py:4: error: '(' was never closed
Command 'suggest' is only valid after a 'check' command (that produces no parse errors)
==
foo.py:4: error: '(' was never closed
-- )

[case testSuggestRefine]
Expand Down
10 changes: 8 additions & 2 deletions test-data/unit/parse.test
Original file line number Diff line number Diff line change
Expand Up @@ -932,16 +932,22 @@ MypyFile:1(
NameExpr(z)))))

[case testNotAsBinaryOp]
x not y # E: invalid syntax
x not y
[out]
main:1: error: invalid syntax
[out version>=3.10]
main:1: error: invalid syntax. Perhaps you forgot a comma?

[case testNotIs]
x not is y # E: invalid syntax
[out]

[case testBinaryNegAsBinaryOp]
1 ~ 2 # E: invalid syntax
1 ~ 2
[out]
main:1: error: invalid syntax
[out version>=3.10]
main:1: error: invalid syntax. Perhaps you forgot a comma?

[case testDictionaryExpression]
{}
Expand Down
Loading