On 09Mar2023 17:55, aapost <aap...@idontexist.club> wrote:
On 3/9/23 16:37, Cameron Simpson wrote:
Just a note that some code formatters use a trailing comma on the last element to make the commas fold points. Both yapf (my preference) and black let you write a line like (and, indeed, flatten if short enough):

    ( a, b, c )

but if you write:

    ( a, b, c, )

they'll fold the lines like:

    ( a,
      b,
      c,
    )
Cameron Simpson <c...@cskk.id.au>


Thanks for the info, good to know, I actually do like the idea of trailing commas for tuples (helps prevent things like the difference between ("abc") and ("abc",) and makes swapping things around nicer.

Just keep in mind that if you restructure code with copy/paste it can be a small issue (not really tied to the trailing comma but commas in general. More than once I've been bitten by doing roughly this:

    f( a,
       b=x+y,
    )

shuffled to:

    b=x+y,
    f( a,
       b=b,
    )

Whoops! It shows up almost immediately, but the first time it took me a while to see that stray comma.

I've just been using a lot of json lately and it has been subconsciously training me different, lol.

Yes, it hates the trailing comma. So annoying.

Cheers,
Cameron Simpson <c...@cskk.id.au>
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to