You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#5340 implements a part of this badly to fix a bug and #5341 adds basic function call formatting.
We need to implement a formatting where the outermost call adds the optional parentheses and formats all inner accesses and calls to not have them add parentheses. A complication is that unlike for if-statements the tree is left recursive, meaning that for a.b().c.d.e the outermost call see an access of e on a.b().c.d, while we must format first a, then .b(), .d and finally .e. We can implement by either collecting into a stack (needs allocation) or using recursing (we most not overrun the recursion and stack limits).
The text was updated successfully, but these errors were encountered:
Implement fluent style/call chains. See the `call_chains.py` formatting
for examples.
This isn't fully like black because in `raise A from B` they allow `A`
breaking can influence the formatting of `B` even if it is already
multiline.
Similarity index:
| project | main | PR |
|--------------|-------|-------|
| build | ??? | 0.753 |
| django | 0.991 | 0.998 |
| transformers | 0.993 | 0.994 |
| typeshed | 0.723 | 0.723 |
| warehouse | 0.978 | 0.994 |
| zulip | 0.992 | 0.994 |
Call chain formatting is affected by
#627, but i'm cutting scope
here.
Closes#5343
**Test Plan**:
* Added a dedicated call chains test file
* The ecosystem checks found some bugs
* I manually check django and zulip formatting
---------
Co-authored-by: Micha Reiser <[email protected]>
Probably wrong place to comment on this, but I don't think black's approach here is sufficient. It only work when the chain is very long, and for fluent definitions you usually want one call per line regardless of the number of calls...
Personally I think a OK compromise would be to use explicit parenthesis around a call-chain as a marker that it should be formatted with one line per call?
Black supports attribute access and call chaining to provide good formatting for fluent interface style programming with extensive method chaining which is common e.g. with django (https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#call-chains):
#5340 implements a part of this badly to fix a bug and #5341 adds basic function call formatting.
We need to implement a formatting where the outermost call adds the optional parentheses and formats all inner accesses and calls to not have them add parentheses. A complication is that unlike for if-statements the tree is left recursive, meaning that for
a.b().c.d.e
the outermost call see an access ofe
ona.b().c.d
, while we must format firsta
, then.b()
,.d
and finally.e
. We can implement by either collecting into a stack (needs allocation) or using recursing (we most not overrun the recursion and stack limits).The text was updated successfully, but these errors were encountered: