10000 Fix a bunch of test broken by python 3.10 (#10404) · python/mypy@42e2bb4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 42e2bb4

Browse files
authored
Fix a bunch of test broken by python 3.10 (#10404)
Python 3.10 changes a bunch of parser error messages. This commit introduces the version>= argument to [out] sections of tests, which allows testing against the new messages on newer python versions.
1 parent 8bc1115 commit 42e2bb4

8 files changed

+178
-17
lines changed

mypy/test/data.py

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,19 +104,43 @@ def parse_test_case(case: 'DataDrivenTestCase') -> None:
104104
full = join(base_path, m.group(1))
105105
deleted_paths.setdefault(num, set()).add(full)
106106
elif re.match(r'out[0-9]*$', item.id):
107-
if item.arg == 'skip-path-normalization':
108-
normalize_output = False
109-
110-
tmp_output = [expand_variables(line) for line in item.data]
111-
if os.path.sep == '\\' and normalize_output:
112-
tmp_output = [fix_win_path(line) for line in tmp_output]
113-
if item.id == 'out' or item.id == 'out1':
114-
output = tmp_output
107+
if item.arg is None:
108+
args = []
115109
else:
116-
passnum = int(item.id[len('out'):])
117-
assert passnum > 1
118-
output2[passnum] = tmp_output
119-
out_section_missing = False
110+
args = item.arg.split(",")
111+
112+
version_check = True
113+
for arg in args:
114+
if arg == 'skip-path-normalization':
115+
normalize_output = False
116+
if arg.startswith("version"):
117+
if arg[7:9] != ">=":
118+
raise ValueError(
119+
"{}, line {}: Only >= version checks are currently supported".format(
120+
case.file, item.line
121+
)
122+
)
123+
version_str = arg[9:]
124+
try:
125+
version = tuple(int(x) for x in version_str.split("."))
126+
except ValueError:
127+
raise ValueError(
128+
'{}, line {}: "{}" is not a valid python version'.format(
129+
case.file, item.line, version_str))
130+
if not sys.version_info >= version:
131+
version_check = False
132+
133+
if version_check:
134+
tmp_output = [expand_variables(line) for line in item.data]
135+
if os.path.sep == '\\' and normalize_output:
136+
tmp_output = [fix_win_path(line) for line in tmp_output]
137+
if item.id == 'out' or item.id == 'out1':
138+
output = tmp_output
139+
else:
140+
passnum = int(item.id[len('out'):])
141+
assert passnum > 1
142+
output2[passnum] = tmp_output
143+
out_section_missing = False
120144
elif item.id == 'triggered' and item.arg is None:
121145
triggered = item.data
122146
else:

test-data/unit/check-errorcodes.test

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ class A:
3131
reveal_type(1) # N: Revealed type is "Literal[1]?"
3232

3333
[case testErrorCodeSyntaxError]
34-
1 '' # E: invalid syntax [syntax]
34+
1 ''
35+
[out]
36+
main:1: error: invalid syntax [syntax]
37+
[out version>=3.10]
38+
main:1: error: invalid syntax. Perhaps you forgot a comma? [syntax]
3539

3640
[case testErrorCodeSyntaxError2]
3741
def f(): # E: Type signature has too many arguments [syntax]

test-data/unit/cmdline.test

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,9 @@ def foo(
753753
[out]
754754
a.py:1: error: unexpected EOF while parsing
755755
== Return code: 2
756+
[out version>=3.10]
757+
a.py:1: error: '(' was never closed
758+
== Return code: 2
756759

757760
[case testParseErrorAnnots]
758761
# cmd: mypy a.py
@@ -1236,6 +1239,10 @@ x: str = 0
12361239
pkg/x.py:1: error: invalid syntax
12371240
Found 1 error in 1 file (errors prevented further checking)
12381241
== Return code: 2
1242+
[out version>=3.10]
1243+
pkg/x.py:1: error: invalid syntax. Perhaps you forgot a comma?
1244+
Found 1 error in 1 file (errors prevented further checking)
1245+
== Return code: 2
12391246

12401247
[case testCmdlinePackageAndFile]
12411248
# cmd: mypy -p pkg file

test-data/unit/fine-grained-blockers.test

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ a.py:1: error: invalid syntax
2323
==
2424
main:2: error: Missing positional argument "x" in call to "f"
2525
==
26+
[out version>=3.10]
27+
==
28+
a.py:1: error: expected ':'
29+
==
30+
main:2: error: Missing positional argument "x" in call to "f"
31+
==
2632

2733
[case testParseErrorShowSource]
2834
# flags: --pretty --show-error-codes
@@ -46,6 +52,16 @@ main:3: error: Missing positional argument "x" in call to "f" [call-arg]
4652
a.f()
4753
^
4854
==
55+
[out version>=3.10]
56+
==
57+
a.py:1: error: expected ':' [syntax]
58+
def f(x: int) ->
59+
^
60+
==
61+
main:3: error: Missing positional argument "x" in call to "f" [call-arg]
62+
a.f()
63+
^
64+
==
4965

5066
[case testParseErrorMultipleTimes]
5167
import a
@@ -66,6 +82,13 @@ a.py:1: error: invalid syntax
6682
a.py:2: error: invalid syntax
6783
==
6884
main:2: error: Missing positional argument "x" in call to "f"
85+
[out version>=3.10]
86+
==
87+
a.py:1: error: expected ':'
88+
==
89+
a.py:2: error: expected ':'
90+
==
91+
main:2: error: Missing positional argument "x" in call to "f"
6992

7093
[case testSemanticAnalysisBlockingError]
7194
import a
@@ -105,6 +128,14 @@ a.py:1: error: invalid syntax
105128
==
106129
main:3: error: Too many arguments for "f"
107130
main:5: error: Too many arguments for "f"
131+
[out version>=3.10]
132+
main:3: error: Too many arguments for "f"
133+
main:5: error: Too many arguments for "f"
134+
==
135+
a.py:1: error: expected ':'
136+
==
137+
main:3: error: Too many arguments for "f"
138+
main:5: error: Too many arguments for "f"
108139

109140
[case testUpdateClassReferenceAcrossBlockingError]
110141
import a
@@ -125,6 +156,11 @@ class C:
125156
a.py:1: error: invalid syntax
126157
==
127158
main:5: error: Missing positional argument "x" in call to "f" of "C"
159+
[out version>=3.10]
160+
==
161+
a.py:1: error: invalid syntax. Perhaps you forgot a comma?
162+
==
163+
main:5: error: Missing positional argument "x" in call to "f" of "C"
128164

129165
[case testAddFileWithBlockingError]
130166
import a
@@ -140,6 +176,13 @@ main:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missin
140176
a.py:1: error: invalid syntax
141177
==
142178
main:2: error: Too many arguments for "f"
179+
[out version>=3.10]
180+
main:1: error: Cannot find implementation or library stub for module named "a"
181+
main:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
182+
==
183+
a.py:1: error: invalid syntax. Perhaps you forgot a comma?
184+
==
185+
main:2: error: Too many arguments for "f"
143186

144187
[case testModifyTwoFilesOneWithBlockingError1]
145188
import a
@@ -216,6 +259,13 @@ a.py:1: error: invalid syntax
216259
a.py:1: error: invalid syntax
217260
==
218261
a.py:2: error: Missing positional argument "x" in call to "f"
262+
[out version>=3.10]
263+
==
264+
a.py:1: error: invalid syntax. Perhaps you forgot a comma?
265+
==
266+
a.py:1: error: invalid syntax. Perhaps you forgot a comma?
267+
==
268+
a.py:2: error: Missing positional argument "x" in call to "f"
219269

220270
[case testModifyTwoFilesIntroduceTwoBlockingErrors]
221271
import a
@@ -280,6 +330,13 @@ a.py:1: error: invalid syntax
280330
main:1: error: Cannot find implementation or library stub for module named "a"
281331
main:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
282332
b.py:1: error: Cannot find implementation or library stub for module named "a"
333+
[out version>=3.10]
334+
==
335+
a.py:1: error: invalid syntax. Perhaps you forgot a comma?
336+
==
337+
main:1: error: Cannot find implementation or library stub for module named "a"
338+
main:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
339+
b.py:1: error: Cannot find implementation or library stub for module named "a"
283340

284341
[case testDeleteFileWithBlockingError-only_when_cache]
285342
-- Different cache/no-cache tests because:
@@ -301,6 +358,13 @@ a.py:1: error: invalid syntax
301358
b.py:1: error: Cannot find implementation or library stub for module named "a"
302359
b.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
303360
main:1: error: Cannot find implementation or library stub for module named "a"
361+
[out version>=3.10]
362+
==
363+
a.py:1: error: invalid syntax. Perhaps you forgot a comma?
364+
==
365+
b.py:1: error: Cannot find implementation or library stub for module named "a"
366+
b.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
367+
main:1: error: Cannot find implementation or library stub for module named "a"
304368

305369
[case testModifyFileWhileBlockingErrorElsewhere]
306370
import a
@@ -324,6 +388,14 @@ a.py:1: error: invalid syntax
324388
==
325389
b.py:2: error: Module has no attribute "f"
326390
b.py:3: error: "int" not callable
391+
[out version>=3.10]
392+
==
393+
a.py:1: error: invalid syntax. Perhaps you forgot a comma?
394+
==
395+
a.py:1: error: invalid syntax. Perhaps you forgot a comma?
396+
==
397+
b.py:2: error: Module has no attribute "f"
398+
b.py:3: error: "int" not callable
327399

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

343420
[case testImportBringsAnotherFileWithSemanticAnalysisBlockingError]
344421
import a
@@ -413,6 +490,13 @@ a.py:1: error: invalid syntax
413490
<ROOT>/test-data/unit/lib-stub/blocker.pyi:2: error: invalid syntax
414491
==
415492
a.py:2: error: "int" not callable
493+
[out version>=3.10]
494+
==
495+
a.py:1: error: invalid syntax. Perhaps you forgot a comma?
496+
==
497+
<ROOT>/test-data/unit/lib-stub/blocker.pyi:2: error: invalid syntax. Perhaps you forgot a comma?
498+
==
499+
a.py:2: error: "int" not callable
416500

417501
[case testInitialBlocker]
418502
# cmd: mypy a.py b.py
@@ -431,6 +515,11 @@ a.py:1: error: invalid syntax
431515
==
432516
b.py:2: error: Incompatible return value type (got "str", expected "int")
433517
==
518+
[out version>=3.10]
519+
a.py:1: error: invalid syntax. Perhaps you forgot a comma?
520+
==
521+
b.py:2: error: Incompatible return value type (got "str", expected "int")
522+
==
434523

435524
[case testDecodeErrorBlocker-posix]
436525
import a

test-data/unit/fine-grained-suggest.test

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,11 @@ foo.py:4: error: unexpected EOF while parsing
10191019
Command 'suggest' is only valid after a 'check' command (that produces no parse errors)
10201020
==
10211021
foo.py:4: error: unexpected EOF while parsing
1022+
[out version>=3.10]
1023+
foo.py:4: error: '(' was never closed
1024+
Command 'suggest' is only valid after a 'check' command (that produces no parse errors)
1025+
==
1026+
foo.py:4: error: '(' was never closed
10221027
-- )
10231028

10241029
[case testSuggestRefine]

test-data/unit/parse.test

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -932,16 +932,22 @@ MypyFile:1(
932932
NameExpr(z)))))
933933

934934
[case testNotAsBinaryOp]
935-
x not y # E: invalid syntax
935+
x not y
936936
[out]
937+
main:1: error: invalid syntax
938+
[out version>=3.10]
939+
main:1: error: invalid syntax. Perhaps you forgot a comma?
937940

938941
[case testNotIs]
939942
x not is y # E: invalid syntax
940943
[out]
941944

942945
[case testBinaryNegAsBinaryOp]
943-
1 ~ 2 # E: invalid syntax
946+
1 ~ 2
944947
[out]
948+
main:1: error: invalid syntax
949+
[out version>=3.10]
950+
main:1: error: invalid syntax. Perhaps you forgot a comma?
945951

946952
[case testDictionaryExpression]
947953
{}

0 commit comments

Comments
 (0)
0