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.

classification
Title: Language Reference - optional comma
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.5, Python 2.7
process
Status: closed Resolution: out of date
Dependencies: 28978 Superseder:
Assigned To: docs@python Nosy List: Joshua.Landau, NeilGirdhar, docs@python, ezio.melotti, jordan, martin.panter
Priority: normal Keywords:

Created on 2014-11-25 19:52 by jordan, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (4)
msg231680 - (view) Author: Jordan (jordan) Date: 2014-11-25 19:52
# I would like to report three bugs in the
# Language Reference Python 3.4.2

#################################
# bug 1: Typo in parameter_list #
#################################

# In 8.6 the rule for parameter_list should be corrected: The first "|" should be "("

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

# This rule was correct in 3.3 but has been changed with issue #21439, I guess.

                    
###############################################################################
# bug 2: print(*(1,2),) is allowed according to the syntax - but not accepted #
###############################################################################

# In 6.3.4:
# call                 ::=  primary "(" [argument_list [","] | comprehension] ")"
# argument_list        ::=  positional_arguments ["," keyword_arguments]
#                             ["," "*" expression] ["," keyword_arguments]
#                             ["," "**" expression]
#                           | keyword_arguments ["," "*" expression]
#                             ["," keyword_arguments] ["," "**" expression]
#                           | "*" expression ["," keyword_arguments] ["," "**" expression]
#                           | "**" expression

# Why is this wrong?
print(1,2,)     # is allowed
print(*(1,2))   # is allowed
#print(*(1,2),) # is allowed according to the syntax - but not accepted

# I guess the trailing comma is only allowed when there is no *-argument
# as it is in the rule for parameter_list

###########################################################
# bug 3: decorator rule allows (aditional) trailing comma #
###########################################################

# In 8.6:
# decorator      ::=  "@" dotted_name ["(" [parameter_list [","]] ")"] NEWLINE
# parameter_list ::=  (defparameter ",")*
#                     ( "*" [parameter] ("," defparameter)* ["," "**" parameter]
#                     | "**" parameter
#                     | defparameter [","] )

# Why is this wrong?
def klammer(klammer_left,klammer_right):
    def klammer_decorator(func):
        def func_wrapper(name):
            return klammer_left + func(name) + klammer_right
        return func_wrapper
    return klammer_decorator

@klammer("<",">",)   # is allowed
#@klammer("<",">",,) # is allowed according to the syntax - but is not accepted
def get_text(name):
    return "Hallo " + name
print(get_text("Uli")) 

@klammer(*("<",">"))   # is allowed
#@klammer(*("<",">"),) # is allowed according to the syntax - but is not accepted
def get_text(name):
    return "Hallo " + name
print(get_text("Uli"))

# I guess the decorator rule might be changed to: 
# decorator      ::=  "@" dotted_name ["(" [parameter_list      ] ")"] NEWLINE
# The other appearences of parameter_list have no optional comma.
msg239080 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-03-24 00:33
See also Issue 9232, about adding support for trailing commas in all cases of function calls and definitions.
msg267830 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-06-08 10:17
Bug 1 is still present in 3.5. In 3.6 it is no longer relevant because the documentation was changed for Issue 9232 (allowing trailing commas in function definitions).

Bug 2 is present in 2.7, but is not relevant to 3.5+. Trailing commas are now allowed in function calls, probably thanks to PEP 448, unpacking generalizations.

Bug 3 has been fixed in Issue 27042.
msg283934 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-12-24 10:09
Issue 28978 covers the parameter list syntax (Bug 1 + plus another problem).
History
Date User Action Args
2022-04-11 14:58:10adminsetgithub: 67131
2021-11-30 23:39:57iritkatrielsetstatus: open -> closed
resolution: out of date
stage: needs patch -> resolved
2016-12-24 10:09:27martin.pantersetdependencies: + a redundant right parentheses in the EBNF rules of parameter_list
messages: + msg283934
2016-06-08 10:17:14martin.pantersetstage: needs patch
messages: + msg267830
versions: + Python 2.7, Python 3.5, - Python 3.4
2015-03-24 00:33:35martin.pantersetnosy: + martin.panter
messages: + msg239080
2015-03-02 08:34:03ezio.melottisetnosy: + Joshua.Landau, NeilGirdhar
2014-11-25 20:15:37ezio.melottisetnosy: + ezio.melotti
2014-11-25 19:52:38jordancreate