Skip to content

Failed to format match-case with nested AS pattern #2746

@Delengowski

Description

@Delengowski

Describe the bug

When trying to run black on a file with a patter matching block where a case is a class pattern with an as pattern inside of it fails to format

To Reproduce

For example, take this code:

A stripped down example of file that was failing

from collections.abc import Callable

class Foo:
    bb = 5

    def aa(self):
        ...


bar1 = Foo()

match bar1:
    case Foo(aa=Callable() as aa, bb=int()):
        print(bar1.aa, bar1.bb)
    case _:
        print("no match", "\n")

And run it with these arguments:

$ black file.py --target-version=py310

The resulting error is:

error: cannot format test.py: Cannot parse: 14:27: case Foo(aa=Callable() as aa, bb=int()):
Oh no! 💥 💔 💥
1 file failed to reformat.

Expected behavior

Expected not to fail

Environment

RHEL7
python 3.10.1
black 21.12b0

Metadata

Metadata

Assignees

No one assigned

    Labels

    T: bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions