Skip to content

Commit 18d5669

Browse files
authored
Fix tests for Python 3.10.1 (2) (#11756)
Followup to #11752. The syntax error changed between 3.10.0 and 3.10.1. https://bugs.python.org/issue46004 I missed a few the first time around unfortunately. https://bugs.python.org/issue46004 Instead of duplicating the original output, I chose to extend the test syntax introduced with #10404 and added support for == version checks.
1 parent 22ab84a commit 18d5669

File tree

4 files changed

+27
-19
lines changed

4 files changed

+27
-19
lines changed

mypy/test/data.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,11 @@ def parse_test_case(case: 'DataDrivenTestCase') -> None:
114114
if arg == 'skip-path-normalization':
115115
normalize_output = False
116116
if arg.startswith("version"):
117-
if arg[7:9] != ">=":
117+
compare_op = arg[7:9]
118+
if compare_op not in {">=", "=="}:
118119
raise ValueError(
119-
"{}, line {}: Only >= version checks are currently supported".format(
120+
"{}, line {}: Only >= and == version checks are currently supported"
121+
.format(
120122
case.file, item.line
121123
)
122124
)
@@ -127,9 +129,17 @@ def parse_test_case(case: 'DataDrivenTestCase') -> None:
127129
raise ValueError(
128130
'{}, line {}: "{}" is not a valid python version'.format(
129131
case.file, item.line, version_str))
130-
if not sys.version_info >= version:
131-
version_check = False
132-
132+
if compare_op == ">=":
133+
version_check = sys.version_info >= version
134+
elif compare_op == "==":
135+
if not 1 < len(version) < 4:
136+
raise ValueError(
137+
'{}, line {}: Only minor or patch version checks '
138+
'are currently supported with "==": "{}"'.format(
139+
case.file, item.line, version_str
140+
)
141+
)
142+
version_check = sys.version_info[:len(version)] == version
133143
if version_check:
134144
tmp_output = [expand_variables(line) for line in item.data]
135145
if os.path.sep == '\\' and normalize_output:

test-data/unit/check-errorcodes.test

+1-3
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@ reveal_type(1) # N: Revealed type is "Literal[1]?"
3434
1 ''
3535
[out]
3636
main:1: error: invalid syntax [syntax]
37-
[out version>=3.10]
37+
[out version==3.10.0]
3838
main:1: error: invalid syntax. Perhaps you forgot a comma? [syntax]
39-
[out version>=3.10.1]
40-
main:1: error: invalid syntax [syntax]
4139

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

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

+9-9
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class C:
156156
a.py:1: error: invalid syntax
157157
==
158158
main:5: error: Missing positional argument "x" in call to "f" of "C"
159-
[out version>=3.10]
159+
[out version==3.10.0]
160160
==
161161
a.py:1: error: invalid syntax. Perhaps you forgot a comma?
162162
==
@@ -176,7 +176,7 @@ main:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missin
176176
a.py:1: error: invalid syntax
177177
==
178178
main:2: error: Too many arguments for "f"
179-
[out version>=3.10]
179+
[out version==3.10.0]
180180
main:1: error: Cannot find implementation or library stub for module named "a"
181181
main:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
182182
==
@@ -259,7 +259,7 @@ a.py:1: error: invalid syntax
259259
a.py:1: error: invalid syntax
260260
==
261261
a.py:2: error: Missing positional argument "x" in call to "f"
262-
[out version>=3.10]
262+
[out version==3.10.0]
263263
==
264264
a.py:1: error: invalid syntax. Perhaps you forgot a comma?
265265
==
@@ -330,7 +330,7 @@ a.py:1: error: invalid syntax
330330
main:1: error: Cannot find implementation or library stub for module named "a"
331331
main:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
332332
b.py:1: error: Cannot find implementation or library stub for module named "a"
333-
[out version>=3.10]
333+
[out version==3.10.0]
334334
==
335335
a.py:1: error: invalid syntax. Perhaps you forgot a comma?
336336
==
@@ -358,7 +358,7 @@ a.py:1: error: invalid syntax
358358
b.py:1: error: Cannot find implementation or library stub for module named "a"
359359
b.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
360360
main:1: error: Cannot find implementation or library stub for module named "a"
361-
[out version>=3.10]
361+
[out version==3.10.0]
362362
==
363363
a.py:1: error: invalid syntax. Perhaps you forgot a comma?
364364
==
@@ -388,7 +388,7 @@ a.py:1: error: invalid syntax
388388
==
389389
b.py:2: error: Module has no attribute "f"
390390
b.py:3: error: "int" not callable
391-
[out version>=3.10]
391+
[out version==3.10.0]
392392
==
393393
a.py:1: error: invalid syntax. Perhaps you forgot a comma?
394394
==
@@ -411,7 +411,7 @@ def f() -> None: pass
411411
<ROOT>/test-data/unit/lib-stub/blocker.pyi:2: error: invalid syntax
412412
==
413413
a.py:1: error: "int" not callable
414-
[out version>=3.10]
414+
[out version==3.10.0]
415415
==
416416
<ROOT>/test-data/unit/lib-stub/blocker.pyi:2: error: invalid syntax. Perhaps you forgot a comma?
417417
==
@@ -490,7 +490,7 @@ a.py:1: error: invalid syntax
490490
<ROOT>/test-data/unit/lib-stub/blocker.pyi:2: error: invalid syntax
491491
==
492492
a.py:2: error: "int" not callable
493-
[out version>=3.10]
493+
[out version==3.10.0]
494494
==
495495
a.py:1: error: invalid syntax. Perhaps you forgot a comma?
496496
==
@@ -515,7 +515,7 @@ a.py:1: error: invalid syntax
515515
==
516516
b.py:2: error: Incompatible return value type (got "str", expected "int")
517517
==
518-
[out version>=3.10]
518+
[out version==3.10.0]
519519
a.py:1: error: invalid syntax. Perhaps you forgot a comma?
520520
==
521521
b.py:2: error: Incompatible return value type (got "str", expected "int")

test-data/unit/parse.test

+2-2
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,7 @@ MypyFile:1(
935935
x not y
936936
[out]
937937
main:1: error: invalid syntax
938-
[out version>=3.10]
938+
[out version==3.10.0]
939939
main:1: error: invalid syntax. Perhaps you forgot a comma?
940940

941941
[case testNotIs]
@@ -946,7 +946,7 @@ x not is y # E: invalid syntax
946946
1 ~ 2
947947
[out]
948948
main:1: error: invalid syntax
949-
[out version>=3.10]
949+
[out version==3.10.0]
950950
main:1: error: invalid syntax. Perhaps you forgot a comma?
951951

952952
[case testSliceInList39]

0 commit comments

Comments
 (0)