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

formatter deviation: line break not occurring on assignments where LHS goes over line-length #11820

Open
jonathan-hill-visasq opened this issue Jun 10, 2024 · 2 comments
Labels
bug Something isn't working formatter Related to the formatter style How should formatted code look

Comments

@jonathan-hill-visasq
Copy link

I'm seeing a case where black is expanding an assignment but ruff is not - even re-writing the black formatted result.

To keep it concise, this example uses an ultra-short line-length of 14:

Input

long_variable_name = 1234

Black:

long_variable_name = (
    1234
)

Ruff:

long_variable_name = 1234

This seems to occur only when the name of the variable assigned to, is longer than line-length (so expanding the line won't bring it within the allowed length).

I can't find this in the documented deviations or other issues at present, and this doesn't seem to be a duplicate of another issue.

@MichaReiser MichaReiser added the formatter Related to the formatter label Jun 10, 2024
@MichaReiser
Copy link
Member

I think this is related to #8940

@MichaReiser MichaReiser added the bug Something isn't working label Jun 10, 2024
@MichaReiser
Copy link
Member

MichaReiser commented Jun 10, 2024

Yes, I can confirm that #8940 would fix the deviation. The problem is, that the PR has a few regressions around call expression formatting, which is why the PR was abandoned. So fixing this requires some more work and is also something that I don't think we can fix outside of a new formatter style guide as it would change how already formatted code gets formatted.

But we should have a second look at this when we work on the next formatter style guide to see if we can match Black more closely.

The main issue here is that Ruff doesn't parenthesize the expression if the ( doesn't fit inside the line length, whereas Black only avoids the parentheses if the content doesn't fit into the line length.

@MichaReiser MichaReiser added the style How should formatted code look label Jun 10, 2024
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 style How should formatted code look
Projects
None yet
Development

No branches or pull requests

2 participants