black icon indicating copy to clipboard operation
black copied to clipboard

Only the last trailing comma in a statement is magic

Open andersk opened this issue 3 years ago • 4 comments

I would expect this to be left alone by the magic trailing comma rule:

zero(
    one,
).two(
    three,
).four(
    five,
)

But Black implodes it to

zero(one,).two(three,).four(
    five,
)

Environment (please complete the following information):

  • Version: 20.8b1
  • OS and Python version: Linux/Python 3.8.5

Does this bug also happen on master? Yes (playground)

andersk avatar Sep 03 '20 03:09 andersk

This is still broken (noting this because a similar bug with the magic trailing comma was fixed).

JelleZijlstra avatar May 29 '21 03:05 JelleZijlstra

This is still broken on v22.3.0. Does anybody have any workarounds?

The only thing I can do now is to put parentheses around the method calls, then black will format the example in the original post like this:

(
    zero(
        one,
    )
    .two(
        three,
    )
    .four(
        five,
    )
)

Or maybe to kickstart potential PRs, can any black maintainer point us to the rough area in the codebase to look at which is causing this issue? Thanks.

thatlittleboy avatar May 01 '22 06:05 thatlittleboy

#2498 has some examples showing this is more general: if a statement contains multiple magic trailing commas, the magic only extends to one of them.

JelleZijlstra avatar Jul 20 '22 13:07 JelleZijlstra

What's the status of this issue? This is still broken on v22.6.0 😞

Toreno96 avatar Aug 04 '22 14:08 Toreno96