-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 undocumented deviation: No wrap in long return #8182
Comments
I'm slightly confused. Black generally tries to avoid parentheses if the parenthesized content also exceeds the line length. We added support for this behavior in #6817 (and refined it later). Now, it seems that this logic doesn't (always?) apply for attribute chains? |
I don't quite understand that either, I wonder if it's intentional. |
I got the same behavior with |
I played with this further and it is correct. Black always wraps attributes in parentheses, even if it doesn't make them fit. Black # fits parenthesized
______ = (
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.bbbbbbbbbbbbbbbbbbbbbbbbbbvvvvvvvvvvvv
)
return (
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.bbbbbbbbbbbbbbbbbbbb
)
# exceeds parenthesized
______ = (
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.bbbbbbbbbbbbbbbbbbbbbbbbbbvvvvvvvvvvvvvvvvv
)
return (
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.bbbbbbbbbbbbbbbbbbbbbbb
)
def doesnt_exceed_line_length_when_parenthesizing():
______ = (
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.bbbbbbbbbbbbbbbbbbbbbbbbbbvvvvvvvv
)
return (
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.bbbbbbbbbbbbbbbb
)
def exceeds_line_length_parenthesized():
______ = (
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.bbbbbbbbbbbbbbbbbbbbbbbbbbvvvvvvvvvvvvvvvvvv
)
return (
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.bbbbbbbbbbbbbbbbbbbbbbbbbb
) Ruff would remove the parentheses for the "exceeds line length" cases. I believe the same is true for call chains. Changing our code to use the normal
Changing the precedence between breaking the target or value has the result that: state[
"event_queue_longpoll_timeout_seconds"
] = settings.EVENT_QUEUE_LONGPOLL_TIMEOUT_SECONDS gets reformatted to state["event_queue_longpoll_timeout_seconds"] = (
settings.EVENT_QUEUE_LONGPOLL_TIMEOUT_SECONDS
) which matches Black's preview style, at least for attributes. I believe implementing the preview style requires changing Changing the precedence regresses our similarity index significantly and I don't know of a good way to make our parenthesizing left to right. The way to achieve this is by:
I don't think it's worth spending time fixing this now, considering that implementing preview style "solves" the problem and it seems rare enough (I didn't find any usages in our baseline projects). Arguably, Ruff's behavior is also more consistent because it uses it for all expressions that are "unsplittable" whereas Black only uses it for some unsplittable expressions. @charliermarsh I propose that we document this as know and intentional deviation. |
I opened an issue on the Black repository to see if omitting parentheses is intentional. psf/black#4001 |
Black considers aligning with ruff's style. |
I recommend us to keep it as for now and see if Black changes their style. |
Can it get added to the documented deviations in the meantime? Edit: I see now that you already suggested that earlier. |
@MichaReiser This is in a return type and not a return value, but is this the same issue? https://play.ruff.rs/88f317d4-7f5a-4d59-8404-a2b117c47caa?secondary=Format |
@henribru yes this seems to be the same issue. Changing the return type to an identifier (remove all dots) makes Black match Ruff's formatting |
Black:
Ruff:
The text was updated successfully, but these errors were encountered: