Strange syntax specification for python decorators

Syntax specification for function definitions :

funcdef        ::=  [decorators] "def" funcname "(" [parameter_list] ")" ["->" expression] ":" suite
decorators     ::=  decorator+
decorator      ::=  "@" dotted_name ["(" [parameter_list [","]] ")"] NEWLINE
dotted_name    ::=  identifier ("." identifier)*
parameter_list ::=  (defparameter ",")*
                    | "*" [parameter] ("," defparameter)* ["," "**" parameter]
                    | "**" parameter
                    | defparameter [","] )
parameter      ::=  identifier [":" expression]
defparameter   ::=  parameter ["=" expression]
funcname       ::=  identifier

The following is supposed to be syntactically valid:

@some.dotted.name(*what : "is this")
def my_func(x):
    pass

However, the translator does not accept. Am I misinterpreting grammar, or is grammar incorrect?

+4
source share
1 answer

Looks like a documentation error.

It was

decorator      ::=  "@" dotted_name ["(" [argument_list [","]] ")"] NEWLINE

to version v3.2 when argument_listchanged to parameter_list. This may not be right, although the one who sent the single-line patch obviously thought otherwise.

the grammar itself has not been changed. He still says:

decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE

And since this:

Python, Python

, , Python , .

+2

All Articles