This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Clarify trailing comma in func arg list
Type: Stage:
Components: Documentation Versions:
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: fdrake Nosy List: brett.cannon, fdrake, terry.reedy
Priority: normal Keywords:

Created on 2003-09-01 16:32 by terry.reedy, last changed 2022-04-10 16:10 by admin. This issue is now closed.

Messages (3)
msg18039 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2003-09-01 16:32
Current Ref Man 5.3.4 Calls says after grammar:
"A trailing comma may be present after an argument 
list but does not affect the semantics. "
But this is not true if arg list ends with *expr or **expr:

>>> dict(*l,) # any function will do since not called
  File "<stdin>", line 1
            ^ # points at ')'
SyntaxError: invalid syntax
>>> dict(**d,)
  File "<stdin>", line 1
            ^ # points at ','
SyntaxError: invalid syntax

Suggestion: "If an argument list does *not* end with 
*expr or **expr, a trailing comma may be added 
without affecting the semantics."

The same exception applies to function defs as well as 
calls, but 7.5 Function definitions does not have a 
statement such as above.  However, the production for 
parameter_list does end with 'defparameter [","]'.  I 
suggest that this be the first of the parenthesized 
alternatives, as it logically should be, rather than the 
last, so it flows better and so that no one (ignorant 
that '[]' binds tighter than '|') could possible think that 
the '[,]' applies to the * and ** parts.  IE: change 

parameter_list  ::=  (defparameter ",")* 
    ("*" identifier [, "**" identifier] 
    | "**" identifier | defparameter [","]) 


parameter_list  ::=  (defparameter ",")* 
    (defparameter [","]
    |'*' identifier [, "**" identifier] 
    | "**" identifier)

Squeezing out a line is a suboptimazation.
msg18040 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2003-09-06 21:42
Logged In: YES 

Terry is right that the line is wrong.  You can examine the actual 
Grammar/Grammar file to see that:

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

As you can see the actual grammar does not even have the 
definition of a 'call' token.  Not only that, but the example in the 
docs is not entirely correct since is says that the * and ** syntax 
take an 'expression' token which in the grammar in the docs is 
basically a tuple-like syntax while the official grammar wants a 
NAME which is defined as a primitive token.

I don't know how extensive of a change is warranted.  That one 
line does need to be changed, but if *only* that line is changed 
then the text won't match the example grammar.  But since the 
example grammar does not mirror the real grammar I don't want 
to go messing with it without Fred weighing in on this.

I am going to assign to Fred to see what he has to say.
msg18041 - (view) Author: Fred Drake (fdrake) (Python committer) Date: 2004-11-02 19:00
Logged In: YES 

I think correcting the text and changing the display of the
grammar is enough to make this better.

Doc/ref/ref5.tex  1.85,
Doc/ref/ref7.tex  1.41,
Date User Action Args
2022-04-10 16:10:58adminsetgithub: 39169
2003-09-01 16:32:49terry.reedycreate