Skip to content

Commit 521e894

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

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

Doc/reference/compound_stmts.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,9 +1216,10 @@ A function definition defines a user-defined function object (see section
12161216
: | `parameter_list_no_posonly`
12171217
parameter_list_no_posonly: `defparameter` ("," `defparameter`)* ["," [`parameter_list_starargs`]]
12181218
: | `parameter_list_starargs`
1219-
parameter_list_starargs: "*" [`parameter`] ("," `defparameter`)* ["," ["**" `parameter` [","]]]
1219+
parameter_list_starargs: "*" [`star_parameter`] ("," `defparameter`)* ["," ["**" `parameter` [","]]]
12201220
: | "**" `parameter` [","]
12211221
parameter: `identifier` [":" `expression`]
1222+
star_parameter: `identifier` [":" ["*"] `expression`]
12221223
defparameter: `parameter` ["=" `expression`]
12231224
funcname: `identifier`
12241225

@@ -1325,7 +1326,8 @@ and may only be passed by positional arguments.
13251326

13261327
Parameters may have an :term:`annotation <function annotation>` of the form "``: expression``"
13271328
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
1329+
``*identifier`` or ``**identifier``. (As a special case, parameters of the form
1330+
``*identifier`` may have an annotation "``: *expression``".) Functions may have "return" annotation of
13291331
the form "``-> expression``" after the parameter list. These annotations can be
13301332
any valid Python expression. The presence of annotations does not change the
13311333
semantics of a function. The annotation values are available as values of
@@ -1336,6 +1338,10 @@ enables postponed evaluation. Otherwise, they are evaluated when the function
13361338
definition is executed. In this case annotations may be evaluated in
13371339
a different order than they appear in the source code.
13381340

1341+
.. versionchanged:: 3.11
1342+
Parameters of the form "``*identifier``" may have an annotation
1343+
"``: *expression``". See :pep:`646` for details.
1344+
13391345
.. index:: pair: lambda; expression
13401346

13411347
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)