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: multiline conditionals wrap differently #7314
Comments
Thanks for reporting this deviation. It isn't specific to bool expression but more generally that Black expands the commented node whereas Ruff does not (because associate the comment with the outer most vs inner most node): Input # A comment in the middle
some_example_var and some_example_var not in some_example_var
a = (
# test
a if b else c
)
a = x[
#test
a + b : b + c
]
a = (
# A comment in the middle
some_example_var and some_example_var not in some_example_var
) Black # A comment in the middle
some_example_var and some_example_var not in some_example_var
a = (
# test
a
if b
else c
)
a = x[
# test
a
+ b : b
+ c
]
a = (
# A comment in the middle
some_example_var
and some_example_var not in some_example_var
) Ruff # A comment in the middle
some_example_var and some_example_var not in some_example_var
a = (
# test
a if b else c
)
a = x[
# test
a + b : b + c
]
a = (
# A comment in the middle
some_example_var and some_example_var not in some_example_var
) I generally prefer Ruff's formatting because it avoids unnecessary line breaks. But eager to hear more opinions. |
Ultimately i think the effect is very marginal either way, but I think perhaps I agree. Particularly with the deviations regarding inline comments, it seems like this gives more control over where the comment "targets", as you can insert more comments to arrive at the same formatting decision otherwise, if it's important to the block of code. Mostly posted so it could get added to the list of intentional deviations, if you were going to keep it. |
Thank you for reporting it. It's extremely helpful for us to have a collection of all deviations because we should either:
So thanks again :) |
We're going to mark this as an intentional deviation for now. Can be closed once it's documented. |
Black wants to split boolean operators across lines, where they're being forced (at least here due to the comment) onto multiple lines:
whereas ruff wants to combine them onto one line:
I dont really have a preference, it was just one of 3 total formatting diffs over 30k LOC (one being a documented intentional diff).
The text was updated successfully, but these errors were encountered: