Skip to content

Commit 842044e

Browse files
JukkaLIvan Levkivskyi
authored and
Ivan Levkivskyi
committed
Don't crash on unsupported Python 3.10 match statement (#11738)
Generate a syntax error instead.
1 parent 9d1d033 commit 842044e

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

mypy/fastparse.py

+4
Original file line numberDiff line numberDiff line change
@@ -1285,6 +1285,10 @@ def visit_Index(self, n: Index) -> Node:
12851285
# cast for mypyc's benefit on Python 3.9
12861286
return self.visit(cast(Any, n).value)
12871287

1288+
def visit_Match(self, n: Any) -> None:
1289+
self.fail("Match statement is not supported",
1290+
line=n.lineno, column=n.col_offset, blocker=True)
1291+
12881292

12891293
class TypeConverter:
12901294
def __init__(self,

mypy/test/testcheck.py

+2
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@
103103
typecheck_files.append('check-python38.test')
104104
if sys.version_info >= (3, 9):
105105
typecheck_files.append('check-python39.test')
106+
if sys.version_info >= (3, 10):
107+
typecheck_files.append('check-python310.test')
106108

107109
# Special tests for platforms with case-insensitive filesystems.
108110
if sys.platform in ('darwin', 'win32'):

test-data/unit/check-python310.test

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[case testMatchStatementNotSupported]
2+
# flags: --python-version 3.10
3+
match str(): # E: Match statement is not supported
4+
case 'x':
5+
1 + ''
6+
case _:
7+
1 + b''

0 commit comments

Comments
 (0)