@@ -1208,18 +1208,15 @@ A function definition defines a user-defined function object (see section
1208
1208
:ref: `types `):
1209
1209
1210
1210
.. productionlist :: python-grammar
1211
- funcdef: [`decorators `] "def" `funcname ` [`type_params `] "(" [`parameter_list `] ")"
1212
- : ["->" `expression `] ":" `suite `
1211
+ funcdef: [`decorators `] "def" `funcname ` [`type_params `] "(" [`parameter_list `] ")" : ["->" `expression `] ":" `suite `
1213
1212
decorators: `decorator`+
1214
1213
decorator: "@" `assignment_expression ` NEWLINE
1215
- parameter_list: `defparameter ` ("," `defparameter `)* "," "/" ["," [`parameter_list_no_posonly `]]
1216
- : | `parameter_list_no_posonly `
1217
- parameter_list_no_posonly: `defparameter ` ("," `defparameter `)* ["," [`parameter_list_starargs `]]
1218
- : | `parameter_list_starargs `
1219
- parameter_list_starargs: "*" [`parameter `] ("," `defparameter `)* ["," ["**" `parameter ` [","]]]
1220
- : | "**" `parameter ` [","]
1221
1214
parameter: `identifier ` [":" `expression `]
1215
+ star_parameter: `identifier ` [":" ["*"] `expression `]
1222
1216
defparameter: `parameter ` ["=" `expression `]
1217
+ parameter_list: `defparameter ` ("," `defparameter `)* "," "/" ["," [`parameter_list_no_posonly `]] : | `parameter_list_no_posonly `
1218
+ parameter_list_no_posonly: `defparameter ` ("," `defparameter `)* ["," [`parameter_list_starargs `]] : | `parameter_list_starargs `
1219
+ parameter_list_starargs: "*" [`star_parameter `] ("," `defparameter `)* ["," ["**" `parameter ` [","]]] : | "**" `parameter ` [","]
1223
1220
funcname: `identifier `
1224
1221
1225
1222
@@ -1323,9 +1320,11 @@ and may only be passed by positional arguments.
1323
1320
single: ->; function annotations
1324
1321
single: : (colon); function annotations
1325
1322
1326
- Parameters may have an :term: `annotation <function annotation> ` of the form "``: expression ``"
1327
- following the parameter name. Any parameter may have an annotation, even those of the form
1328
- ``*identifier `` or ``**identifier ``. Functions may have "return" annotation of
1323
+ Parameters may have an :term: `annotation <function annotation> ` of the form
1324
+ "``: expression ``" following the parameter name. Any parameter may have an
1325
+ annotation, even those of the form ``*identifier `` or ``**identifier ``.
1326
+ (As a special case, parameters of the form ``*identifier `` may have an
1327
+ annotation "``: *expression ``".) Functions may have "return" annotation of
1329
1328
the form "``-> expression ``" after the parameter list. These annotations can be
1330
1329
any valid Python expression. The presence of annotations does not change the
1331
1330
semantics of a function. The annotation values are available as values of
@@ -1336,6 +1335,10 @@ enables postponed evaluation. Otherwise, they are evaluated when the function
1336
1335
definition is executed. In this case annotations may be evaluated in
1337
1336
a different order than they appear in the source code.
1338
1337
1338
+ .. versionchanged :: 3.11
1339
+ Parameters of the form "``*args ``" may have an annotation
1340
+ "``: *expression ``". See :pep: `646 ` for details.
1341
+
1339
1342
.. index :: pair: lambda; expression
1340
1343
1341
1344
It is also possible to create anonymous functions (functions not bound to a
0 commit comments