[issue10682] With '*args' or even bare '*' in def/call argument list, trailing comma causes SyntaxError

Mike Lissner report at bugs.python.org
Tue Mar 29 14:48:27 EDT 2016


Mike Lissner added the comment:

This is an old issue, but where I run into it frequently is when I use the format function and string interpolation. For example, this throws a SyntaxError:

"The name of the person is {name_first} {name_last}".format(
    **my_obj.__dict__,
)

Because strings tend to be fairly long, it's pretty common that the arguments to format end up on their own line. 

I was always taught to use trailing commas in Python, and I'm fanatical about ensuring they're there. It's a smart part of the language that saves you from many bugs and much typing when copy/pasting/tweaking. 

This is the first time I've ever run into an implementation bug in CPython, and at least from the post on StackOverflow, this looks like the parser isn't obeying the grammar: https://stackoverflow.com/questions/16950394/python-why-is-this-invalid-syntax

----------
nosy: +Mike.Lissner

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue10682>
_______________________________________


More information about the Python-bugs-list mailing list