black: Inconsistent wrapping for long call chain
Method chaining is inconsistent when the overall expression is a call (rather than, say, an assignment). Not sure if this is a style change or a bug.
Describe the style change
It would be great if black were consistent in its wrapping such that it either chained horizontally or vertically, but not both within the same expression (at least within the same level in the call-nesting of an expression).
Examples in the current Black style
def func():
thing("argument-1").thing("argument-2").thing("argument-3").thing(
"argument-4",
).thing("argument-5").thing("argument-6").thing("argument-7").thing(
"argument-8",
).thing(
"argument-9",
).thing(
"argument-10"
).thing(
"argument-11"
).thing(
"argument-12"
)
Adding trailing commas doesn’t help, though I understand that that’s a separate issue (https://github.com/psf/black/issues/1671):
def func():
thing("argument-1",).thing("argument-2",).thing("argument-3",).thing(
"argument-4",
).thing("argument-5",).thing("argument-6",).thing("argument-7",).thing(
"argument-8",
).thing(
"argument-9",
).thing(
"argument-10"
).thing(
"argument-11"
).thing(
"argument-12"
)
Desired style
def func():
thing(
"argument-1",
).thing(
"argument-2",
).thing(
"argument-3",
).thing(
"argument-4",
).thing(
"argument-5",
).thing(
"argument-6",
).thing(
"argument-7",
).thing(
"argument-8",
).thing(
"argument-9",
).thing(
"argument-10"
).thing(
"argument-11"
).thing(
"argument-12"
)
Additional context
Possibly related issues:
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 7
- Comments: 15
Actually, in line with the documentation, I’d expect it to be formatted like this:
which Black does keep (playground), but doesn’t quite produce.
Oh, indeed! It should be #571 👍
I agree that https://github.com/psf/black/issues/2279#issuecomment-863304112 is better than the current output, however due to the presence of trailing commas here I would expect that this would be wrapped as in my original report. I’m not sure what black should do given a similar input which didn’t have trailing commas.
We have that, it’s called
# fmt: off.