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
I understand that first call is not on a new line because of reasons, but the rest still looks quite odd, especially considering that when there are three calls in the chain, Black produces
Reacted by RobinRamael, Paulo Alem, Tushar Chandra, Maximilian Roos, Edoardo Abati, Robert Martin, Markus Piotrowski, Marti Raudsepp, Mark Gregson, Isaac Virshup and 39 more
I would prefer that black applies the fluent style across more cases of chained calls and attribute accesses, such as those examples provided above, even if it does use a few more lines. Consistency between these similar multi-line expressions is more valuable to me than removing a few extra lines.
Reacted by Italo Silva, Duncan Mortimer, Amund Vedal, Filip Ε tamcar, Giuliano Albanese, niqzart, Azat Akhmetov, FSpanhel, Cliff Wells, joshdunnlime and 3 more
Since there are no maintainer comments yet on this issue, I'll echo the points already raised: I'd also like for Black to format fluent interfaces with or without initial parens consistently:
adding the parens rather than splitting a single call if the line is too long.
Reacted by BjΓΆrn LindstrΓΆm, Marcio Cruz, niqzart, Azat Akhmetov, joshdunnlime, Gustavo Maia, Alexander C, Gaultier LE MEUR, Jerin Varghese, Anderson and 2 more
Here's a more complete set of variations I'd expect to behave similarly: playground
Regardless of the presence of initial surrounding parentheses, if the line is too long and there is a call chain we should add parens and split on method/attribute access (dots)
Whether or not the expression is an assignment should have no effect on the call chain formatting
Whether or not the calls contain any arguments should also not have an effect on the formatting beyond splitting further if the call itself is too long, unless:
Having magic trailing commas should explode the calls as normal
In the example playground, I find that the cases with no assignment and no initial parens are formatted against my expectations.
It would indeed be much appreciated if the formatting of fluent interfaces were more consistent. The examples posted by @max-sixty above are very descriptive of the issue.
With method chaining is often better for readability to have more lines but every method in the chain being called in a new line
Please write a PR to fix this issue instead of sending unproductive comments.
Reacted by Frank Sachsenheim, Leo Fleskes and cobalt
Reacted by Azat Akhmetov, doublethink13, cpanagio, Gaultier LE MEUR, Gleb Khaykin, Andrew Zhu, Topher, Nils Vreman, Derek Loewen, Felipe Arisi and 1 more
which is way less readable. I know you're looking for PR's, @JelleZijlstra , but not everyone is in the open source community business. Comments like this are just the users of these open source packages hoping to influence the prioritisation a little bit.
not everyone is in the open source community business. Comments like this are just the users of these open source packages hoping to influence the prioritisation a little bit.
There is no "business" and there is no "prioritisation". There are only PRs. Everyone here is a volunteer.
I'm locking this issue to prevent more unproductive notifications for the many people interested in this issue. PRs are still welcome!
Activity
max-sixty commentedon Mar 1, 2019
Forgive me for using this as the fluent questions thread, but another case:
With a single call
With two calls
Why the switch of the first line between the two?
I would generally prefer the second format even without the second call (though the question stands independent of my opinion)
max-sixty commentedon Mar 21, 2019
Adding another here, as a (hopefully) helpful additional case:
From:
To:
max-sixty commentedon May 30, 2019
And another:
Looks good:
Now without the
()on the last two lines afterstatus&completion_time:MrkGrgsn commentedon Mar 10, 2020
I would prefer that black applies the fluent style across more cases of chained calls and attribute accesses, such as those examples provided above, even if it does use a few more lines. Consistency between these similar multi-line expressions is more valuable to me than removing a few extra lines.
vedal commentedon Feb 11, 2021
Is this possible to define flhent interface in black settings?
peterHoburg commentedon Oct 20, 2021
Related to my comment: #2279 (comment)
felix-hilden commentedon Jan 31, 2022
Since there are no maintainer comments yet on this issue, I'll echo the points already raised: I'd also like for Black to format fluent interfaces with or without initial parens consistently:
adding the parens rather than splitting a single call if the line is too long.
felix-hilden commentedon Jan 31, 2022
Here's a more complete set of variations I'd expect to behave similarly: playground
In the example playground, I find that the cases with no assignment and no initial parens are formatted against my expectations.
PeterJCLaw commentedon Jan 31, 2022
From #571 (comment) I suggest we add to the list:
felix-hilden commentedon Jan 31, 2022
And in that case, #510 is very relevant, if not duplicate. But I'll leave it open for now.
joshdunnlime commentedon Mar 18, 2023
Anything here?
joaomacalos commentedon May 1, 2023
It would indeed be much appreciated if the formatting of fluent interfaces were more consistent. The examples posted by @max-sixty above are very descriptive of the issue.
With method chaining is often better for readability to have more lines but every method in the chain being called in a new line
vmgustavo commentedon Jul 31, 2023
anything here? this is currently the only thing that is holding me back from using black
JelleZijlstra commentedon Jul 31, 2023
Please write a PR to fix this issue instead of sending unproductive comments.
joaomacalos commentedon Aug 2, 2023
@vmgustavo I'm using
# fmt : skipafter the closing parenthesis of my fluent chains to keep my formatting when black breaks it.ion-elgreco commentedon Aug 10, 2023
@JelleZijlstra is it possible to provide custom method chains? So, this issue gets avoided, or is skipping format the only option here?
mo2menelzeiny commentedon Mar 26, 2024
can we disable this with a flag?
leotrs commentedon Nov 24, 2024
Any comments from a maintainer? This feature would benefit the scientific Python community greatly since pandas encourages method chaining so much.
tijlk commentedon Nov 25, 2024
I'm using a lot of PySpark, and the following
annoyingly gets formatted by black as:
which is way less readable. I know you're looking for PR's, @JelleZijlstra , but not everyone is in the open source community business. Comments like this are just the users of these open source packages hoping to influence the prioritisation a little bit.
hauntsaninja commentedon Nov 26, 2024
There is no "business" and there is no "prioritisation". There are only PRs. Everyone here is a volunteer.
I'm locking this issue to prevent more unproductive notifications for the many people interested in this issue. PRs are still welcome!