method (a, b = '', *c, **d): gets a syntax error?
Terry Reedy
tjreedy at udel.edu
Mon Sep 1 12:36:52 EDT 2003
>(Gerrit Holl) Python 2.3 does the same.
>
> Python 2.3 (#1, Aug 5 2003, 14:13:25)
> [GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2
> Type "help", "copyright", "credits" or "license" for more
information.
> 0 >>> zip(**(),)
> File "<stdin>", line 1
> zip(**(),)
> ^
> SyntaxError: invalid syntax
> 1 >>> def foo(**a,): pass
> File "<stdin>", line 1
> def foo(**a,): pass
> ^
> SyntaxError: invalid syntax
Thank you for the verification. I have submitted doc bug report SF
798652
>(Michael Hudson): Because that's what the grammar says
After the grammer in 5.3.4 follows :"A trailing comma may be present
after an argument list but does not affect the semantics. " I
suggested instead "If an argument list does *not* end with *expr or
**expr, a trailing comma may be added without affecting the
semantics."
I also suggested a change in 7.5 Function definitions to the
production for parameter_list.
>(Piet von Oostrum) [Explanation of why '**dic,)' should be error]
I agree, which is why I filed as doc bug. Note
>>> def fl(*lis,): pass
File "<stdin>", line 1
def fl(*lis,): pass
^ # points at ')'
SyntaxError: invalid syntax
The error is detected as ')' instead of ',' because **dic could have
followed, but didn't.
Terry J. Reedy
More information about the Python-list
mailing list