Skip to content

Commit 1c6fbd1

Browse files
committed
Update language reference for PEP 646
1 parent 34f5ae6 commit 1c6fbd1

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

Doc/reference/compound_stmts.rst

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,18 +1208,15 @@ A function definition defines a user-defined function object (see section
12081208
:ref:`types`):
12091209

12101210
.. 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`
12131212
decorators: `decorator`+
12141213
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` [","]
12211214
parameter: `identifier` [":" `expression`]
1215+
star_parameter: `identifier` [":" ["*"] `expression`]
12221216
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` [","]
12231220
funcname: `identifier`
12241221

12251222

@@ -1323,9 +1320,11 @@ and may only be passed by positional arguments.
13231320
single: ->; function annotations
13241321
single: : (colon); function annotations
13251322

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
13291328
the form "``-> expression``" after the parameter list. These annotations can be
13301329
any valid Python expression. The presence of annotations does not change the
13311330
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
13361335
definition is executed. In this case annotations may be evaluated in
13371336
a different order than they appear in the source code.
13381337

1338+
.. versionchanged:: 3.11
1339+
Parameters of the form "``*args``" may have an annotation
1340+
"``: *expression``". See :pep:`646` for details.
1341+
13391342
.. index:: pair: lambda; expression
13401343

13411344
It is also possible to create anonymous functions (functions not bound to a

Doc/reference/expressions.rst

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -873,9 +873,13 @@ primary is subscripted, the evaluated result of the expression list will be
873873
passed to one of these methods. For more details on when ``__class_getitem__``
874874
is called instead of ``__getitem__``, see :ref:`classgetitem-versus-getitem`.
875875

876-
If the expression list contains at least one comma, it will evaluate to a
877-
:class:`tuple` containing the items of the expression list. Otherwise, the
878-
expression list will evaluate to the value of the list's sole member.
876+
If the expression list contains at least one comma, or if any of the expressions
877+
is starred, the expression list will evaluate to a :class:`tuple` containing the
878+
items of the expression list. Otherwise, the expression list will evaluate to
879+
the value of the list's sole member.
880+
881+
.. versionchanged:: 3.11
882+
Expressions in an expression list may be starred. See :pep:`646` for details.
879883

880884
For built-in objects, there are two types of objects that support subscription
881885
via :meth:`~object.__getitem__`:
@@ -1874,7 +1878,7 @@ Expression lists
18741878
single: , (comma); expression list
18751879

18761880
.. productionlist:: python-grammar
1877-
expression_list: `expression` ("," `expression`)* [","]
1881+
expression_list: `starred_expression` ("," `starred_expression`)* [","]
18781882
starred_list: `starred_item` ("," `starred_item`)* [","]
18791883
starred_expression: `expression` | (`starred_item` ",")* [`starred_item`]
18801884
starred_item: `assignment_expression` | "*" `or_expr`
@@ -1898,6 +1902,9 @@ the unpacking.
18981902
.. versionadded:: 3.5
18991903
Iterable unpacking in expression lists, originally proposed by :pep:`448`.
19001904

1905+
.. versionadded:: 3.11
1906+
Any item in an expression list may be starred. See :pep:`646`.
1907+
19011908
.. index:: pair: trailing; comma
19021909

19031910
A trailing comma is required only to create a one-item tuple,

0 commit comments

Comments
 (0)