Skip to content

Commit

Permalink
Don't crash on unsupported Python 3.10 match statement (#11738)
Browse files Browse the repository at this point in the history
Generate a syntax error instead.
  • Loading branch information
JukkaL authored and Ivan Levkivskyi committed Dec 15, 2021
1 parent 9d1d033 commit 842044e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions mypy/fastparse.py
Expand Up @@ -1285,6 +1285,10 @@ def visit_Index(self, n: Index) -> Node:
# cast for mypyc's benefit on Python 3.9
return self.visit(cast(Any, n).value)

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


class TypeConverter:
def __init__(self,
Expand Down
2 changes: 2 additions & 0 deletions mypy/test/testcheck.py
Expand Up @@ -103,6 +103,8 @@
typecheck_files.append('check-python38.test')
if sys.version_info >= (3, 9):
typecheck_files.append('check-python39.test')
if sys.version_info >= (3, 10):
typecheck_files.append('check-python310.test')

# Special tests for platforms with case-insensitive filesystems.
if sys.platform in ('darwin', 'win32'):
Expand Down
7 changes: 7 additions & 0 deletions test-data/unit/check-python310.test
@@ -0,0 +1,7 @@
[case testMatchStatementNotSupported]
# flags: --python-version 3.10
match str(): # E: Match statement is not supported
case 'x':
1 + ''
case _:
1 + b''

0 comments on commit 842044e

Please sign in to comment.