match/case 语句在 PyCharm 中引发 SyntaxError

match/case statement raises SyntaxError in PyCharm

我想使用 match/case 语句,但目前 PyCharm 不喜欢它,当我尝试 运行 时,此代码:

def test(action):
    match action:
        case "send":
            pass
        case "create":
            pass
        case "dump":
            pass

它告诉我

    match action:
          ^
SyntaxError: invalid syntax

我使用 python 3.9.1 和 PyCharm 2021.2.3 Pro。关键字 matchcase 是蓝色的,所以我猜 PyCharm 可以识别它们但不能 运行。我在这里错过了什么?

您使用的 Python 版本低于 3.10。

PEP 634: Structural Pattern Matching is introduced in python 3.10. See What’s New In Python 3.10 获取更多信息。