What is better to do?
self.call(1, True, \"hi\")
or
self.call(1, True, \"hi\",)
And what in the following
I'll also leave my 2 cents here, even if this thread has been here for quite some time, it might benefit somebody :)
PEP8 actually does say when to use trailing commas and if you follow their recommendations (not mandatory, but definitely recommended) then the second one-liner example of yours can be ruled out, i.e:
No:
self.call(1, True, "hi",)
Yes:
self.call(
1,
True,
"hi",
)
Usages in function calls (use sparingly to never) and here's why:
One of the coding principles is that a function should do one thing, and one thing only. So seeing a trailing comma there, a lot of questions may arise, when they really shouldn't. Normally when you see a trailing comma somewhere, you expect that thing to change over time. So if it's a list, tuple, dict, etc. it usually indicates that whoever designed it, did it with the intention of physically adding or removing or switching lines in that structure, and well... you don't see that with functions that much, or at least you shouldn't, and if you do, a better design should be considered.
As aforementioned, a function should also be very predictable, you don't design a function to send mail and rockets to the moon at the same time, and leave a trailing comma when calling to send the mail because who knows when you might send rockets and you want less cluttered diff (it will only cause more confusion and its a poor design)
An arbitrary number of parameters (or even a fixed, but large number of parameters) usually indicates that either you are instantiating an object there, or you are doing multiple things, when really what you should be doing is split your design into creating multiple smaller functions, that each do one thing, hence, no trailing comma needed.
Also consider, even if you did have a function, which you would be able to call with multiple number of parameters, think about how often would you do that and what it implies? Well that would imply something like:
Actual usages
Trailing commas make sense, like you said in data structures, data structures that are expected to change physically over time, because if you change it at run-time, well it wouldn't make any sense for anything that's in the editor, except for the definition which might as well be an empty structure []
xD
Where data structures (lists, dicts, sets, tuples, etc) are expected to change (physically, the source code) then trailing commas are actually recommended and actually useful (see the full PEP link, it has use cases and recommendations)
Conclusion: