It looks wrong to me, but I went through PEP 8, and didn’t find any guidance on this style. PEP 8 does talk about operators at the beginning of multi-lines, but I couldn’t find anything about leading commas. I could imagine an argument for it, but it seems quite unusual and non-standard.
Did I miss a bit in PEP 8? Should this style be discouraged? Should that be in PEP 8?
Under Pet Peeves, there is a mention to “Avoid extraneous whitespace […] Immediately before a comma.” That teeeechnically implies that you shouldn’t use leading commas (which necessarily have whitespace before them in the form of a newline/indentation…)
Leading commas are a quirk used in languages that don’t allow trailing commas. You can add another line to the function call and still have a one-line diff.
Python allows trailing commas, so we get the benefit without tortured typography:
It’s a monstrosity that’s common in SQL code. I believe the logic is that it makes adding lines easier (somehow) when final trailing commas aren’t allowed. There’s no reason for it in Python, and it should be discouraged in Python code. Personally, I don’t think it needs to be in PEP 8, it’s covered by the fundamental rule of “don’t write ugly code”.
Since when did style guides become “if it’s not explicitly discouraged, it’s permissible”?
Here’s a fun Tim Peters anecdote. We came across this style at PythonLabs and we were all horrified. Tim qualified in a slightly off-color joke, saying “No matter how you shake and dance…” and a huge grin.
It would make for slightly cleaner diffs (only one line added rather than 1 deleted 2 added) but I personally don’t agree with slightly cleaner diffs at the expense of significantly uglier code lol
Hmmm, not a fan.
I prefer the comma on the end of every line. That makes it slightly easier to add extra lines, (that is, in this case, further (long) keyword arguments), and also sort a block of lines (more relevant for a list of items).
The code I’ve just read is one of the most insanely idiotic things I have ever seen. At no point in its rambling, incoherent syntax was it even close to anything that could be considered a rational code style. Everyone on this thread is now dumber for having looked at it. I award it no points, and may God have mercy on its soul.