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

Invalid formatting of match statement #9394

Closed
MSDehghan opened this issue Jan 4, 2024 · 3 comments
Closed

Invalid formatting of match statement #9394

MSDehghan opened this issue Jan 4, 2024 · 3 comments
Assignees
Labels
bug Something isn't working formatter Related to the formatter

Comments

@MSDehghan
Copy link

MSDehghan commented Jan 4, 2024

formatting below code with ruff format file.py command leads to invalid python code:

match {}:
    case {
        "long_long_long_key": str(long_long_long_key)
    } if value := "long long long long long long long long long long long value":
        pass

after formatting with ruff the file will look like this which is not a valid python code:

match {}:
    case {"long_long_long_key": str(long_long_long_key)} if value
    := "long long long long long long long long long long long value":
        pass

ruff version: 0.1.11

@zanieb zanieb added bug Something isn't working formatter Related to the formatter labels Jan 4, 2024
@zanieb
Copy link
Member

zanieb commented Jan 4, 2024

Can reproduce this with ruff 0.1.11 (fefc7e819 2024-01-02) with and without the --preview flag, thanks for the report!

@charliermarsh
Copy link
Member

I can take a look -- thanks for this.

@charliermarsh charliermarsh self-assigned this Jan 5, 2024
charliermarsh added a commit that referenced this issue Jan 8, 2024
## Summary

This is an attempt to solve
#9394 by avoiding breaks in
named expressions when invalid.
@charliermarsh
Copy link
Member

Fixed by #9396. Thanks!

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

No branches or pull requests

3 participants