From cb4cdbc652362c544682d6c75953eeba98c22f34 Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Tue, 14 Dec 2021 14:49:02 +0000 Subject: [PATCH] Don't crash on unsupported Python 3.10 match statement Generate a syntax error instead. --- mypy/fastparse.py | 4 ++++ mypy/test/testcheck.py | 2 ++ test-data/unit/check-python310.test | 7 +++++++ 3 files changed, 13 insertions(+) create mode 100644 test-data/unit/check-python310.test diff --git a/mypy/fastparse.py b/mypy/fastparse.py index a0d0ec8e34b0..bd348e6a0237 100644 --- a/mypy/fastparse.py +++ b/mypy/fastparse.py @@ -1286,6 +1286,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, diff --git a/mypy/test/testcheck.py b/mypy/test/testcheck.py index 642721c1b073..355a400168f6 100644 --- a/mypy/test/testcheck.py +++ b/mypy/test/testcheck.py @@ -104,6 +104,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'): diff --git a/test-data/unit/check-python310.test b/test-data/unit/check-python310.test new file mode 100644 index 000000000000..3bcac61855b4 --- /dev/null +++ b/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''