Skip to content

Commit b2c9296

Browse files
authored
Don't crash on unsupported Python 3.10 match statement (#11738)
Generate a syntax error instead.
1 parent bb934e9 commit b2c9296

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
@@ -1286,6 +1286,10 @@ def visit_Index(self, n: Index) -> Node:
12861286
# cast for mypyc's benefit on Python 3.9
12871287
return self.visit(cast(Any, n).value)
12881288

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

12901294
class TypeConverter:
12911295
def __init__(self,

mypy/test/testcheck.py

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

108110
# Special tests for platforms with case-insensitive filesystems.
109111
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)