Skip to content

Enable pattern matching syntax by default #2662

@thisisrandy

Description

@thisisrandy

Describe the bug
PEP 634 introduces structural pattern matching in python 3.10. Black at 21.11b1 (latest) does not seem to support this new syntax.

To Reproduce

Here is a basic example of the new syntax, which we will save in match_test.py:

foo = "str"
match foo:
    case str():
        print("string!")
    case int():
        print("int!")
    case _:
        print("something else!")
> python --version
Python 3.10.0

> python match_test.py
string!

> python -m black --version
python -m black, 21.11b1 (compiled: no)

> python -m black match_test.py
error: cannot format match_test.py: Cannot parse: 2:6: match foo:
Oh no! 💥 💔 💥
1 file failed to reformat.

Expected behavior

Structural pattern matching (and all other new python 3.10 syntax) should be fully supported.

Environment

  • Black's version: 21.11b1
  • OS and Python version: Ubuntu 20.04.3 LTS/Python 3.10.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    C: target versionRelated to --target-version, e.g. autodetectionS: needs discussionNeeds further hashing out before ready for implementation (on desirability, feasibility, etc.)T: enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions