Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Delengowski opened this issue Jan 4, 2022 · 2 comments · Fixed by #2749
Closed

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

Delengowski opened this issue Jan 4, 2022 · 2 comments · Fixed by #2749
Labels
T: bug Something isn't working

Comments

@Delengowski
Copy link

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

@Delengowski Delengowski added the T: bug Something isn't working label Jan 4, 2022
@Delengowski Delengowski changed the title Failed to format match-case with AS pattern Failed to format match-case with nested AS pattern Jan 4, 2022
@Delengowski
Copy link
Author

I believe this is related to #1948

@isidentical
Copy link
Collaborator

I can verify this bug, and confirm it is a grammar inconsistency. Will submit a PR tonight.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants