Python 3 grammar, function parameters

Junkman j at junkwallah.org
Mon Jul 12 18:32:27 EDT 2010


Greetings to Python users,

I'm trying to parse Python code using the grammar supplied with the
documentation set, and have a question on the grammar for function
parameters:

funcdef: 'def' NAME parameters ['->' test] ':' suite
parameters: '(' [typedargslist] ')'
typedargslist: ((tfpdef ['=' test] ',')*
                ('*' [tfpdef] (',' tfpdef ['=' test])* [',' '**' tfpdef]
| '**' tfpdef)
                | tfpdef ['=' test] (',' tfpdef ['=' test])* [','])
tfpdef: NAME [':' test]

>From what I understand, a naked asterisk - i.e. it is not a prefix to an
identifier - is not a valid parameter, but the grammar  explicitly
allows it by making the  identifier that immediately follows the
asterisk optional.

Are there cases where naked asterisk is allowed as a function
parameter?  If not, would it be correct for the grammar to specify the
identifier trailing asterisk as mandatory?

Thanks for any insight.

Jay  



More information about the Python-list mailing list