-
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: With
/ AsyncWith
(includes WithItem
)
#5368
Comments
@davidszotten do you want to look into/plan to work on generalizing the logic by either defining an union enum or a trait for |
sure, will take a look |
I'm not sure how to handle this inside of the formatter but we're currently adding to many parentheses for # Input
with (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb) as c:
...
# Ruff Output
with (
(
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
) as c,
):
...
# Black
with (
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
) as c:
... Because both the binary expression and the Other interesting patterns with (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb) as c, (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb) as c:
...
with (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb), (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb):
...
with aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb as c, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb as c:
... We don't need to match black precisely but I do prefer black's formatting overall. We can tackle this in a separate PR and I can also look into it |
i was trying to follow the code to understand how |
That's correct. An outer group always expands if an inner group expands. I'm on my phone but there's a propagate_expands that implements this behavior. A sequence of groups expands the groups from right to left Best fitting allows you to provide multiple versions of the same content and the printer tries to pick the first one that fits (or falls back to an expanded version) If group breaks accepts an optional with_group. It makes the content dependent on whatever the group with that given id expands rather than the enclosing group. However, the referred group must either be a parent or precede the content. I think that summarizes most grouping IR elements. In this case, it may be necessary that we enumerate all expressions for which we don't want parantheses. |
ok. might leave this for you (separate pr seems ok) |
With
format StmtWith #5350AsyncWith
WithItem
The text was updated successfully, but these errors were encountered: