[issue2009] Grammar change to prevent shift/reduce problem with varargslist

Mark Dickinson report at bugs.python.org
Fri Jul 9 11:28:07 CEST 2010


Mark Dickinson <dickinsm at gmail.com> added the comment:

+!. I had to do a very similar refactoring recently when trying to fix the parser module to understand keyword-only arguments and annotations.

Taking keyword-only arguments into account, I think the replacement needs to be:

varargslist: (vfpdef ['=' test] (',' vfpdef ['=' test])* [',' 
   ['*' [vfpdef] (',' vfpdef ['=' test])* [',' '**' vfpdef] | '**' vfpdef]]
 |  '*' [vfpdef] (',' vfpdef ['=' test])* [',' '**' vfpdef] | '**' vfpdef)

and the analogous replacement needs to be made in the production for 'typedargslist', too.

BTW, I'm a bit surprised that the grammar doesn't allow for trailing commas after keyword-only arguments:  that is,

def f(a, b,): ...     is fine, but
def f(*, a, b,): ...  is a SyntaxError

----------
nosy: +mark.dickinson

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


More information about the Python-bugs-list mailing list