Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Language Reference - optional comma #67131

Closed
Jordan mannequin opened this issue Nov 25, 2014 · 4 comments
Closed

Language Reference - optional comma #67131

Jordan mannequin opened this issue Nov 25, 2014 · 4 comments
Labels
docs Documentation in the Doc dir type-feature A feature request or enhancement

Comments

@Jordan
Copy link
Mannequin

Jordan mannequin commented Nov 25, 2014

BPO 22942
Nosy @ezio-melotti, @vadmium, @NeilGirdhar
Dependencies
  • bpo-28978: a redundant right parentheses in the EBNF rules of parameter_list
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-11-30.23:39:57.131>
    created_at = <Date 2014-11-25.19:52:38.014>
    labels = ['type-feature', 'docs']
    title = 'Language Reference - optional comma'
    updated_at = <Date 2021-11-30.23:39:57.131>
    user = 'https://bugs.python.org/jordan'

    bugs.python.org fields:

    activity = <Date 2021-11-30.23:39:57.131>
    actor = 'iritkatriel'
    assignee = 'docs@python'
    closed = True
    closed_date = <Date 2021-11-30.23:39:57.131>
    closer = 'iritkatriel'
    components = ['Documentation']
    creation = <Date 2014-11-25.19:52:38.014>
    creator = 'jordan'
    dependencies = ['28978']
    files = []
    hgrepos = []
    issue_num = 22942
    keywords = []
    message_count = 4.0
    messages = ['231680', '239080', '267830', '283934']
    nosy_count = 6.0
    nosy_names = ['ezio.melotti', 'docs@python', 'martin.panter', 'Joshua.Landau', 'NeilGirdhar', 'jordan']
    pr_nums = []
    priority = 'normal'
    resolution = 'out of date'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue22942'
    versions = ['Python 2.7', 'Python 3.5']

    @Jordan
    Copy link
    Mannequin Author

    Jordan mannequin commented Nov 25, 2014

    # 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 bpo-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.

    @Jordan Jordan mannequin assigned docspython Nov 25, 2014
    @Jordan Jordan mannequin added docs Documentation in the Doc dir type-feature A feature request or enhancement labels Nov 25, 2014
    @vadmium
    Copy link
    Member

    vadmium commented Mar 24, 2015

    See also bpo-9232, about adding support for trailing commas in all cases of function calls and definitions.

    @vadmium
    Copy link
    Member

    vadmium commented Jun 8, 2016

    Bug 1 is still present in 3.5. In 3.6 it is no longer relevant because the documentation was changed for bpo-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 bpo-27042.

    @vadmium
    Copy link
    Member

    vadmium commented Dec 24, 2016

    bpo-28978 covers the parameter list syntax (Bug 1 + plus another problem).

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    docs Documentation in the Doc dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants