@@ -423,7 +423,7 @@ Yield expressions
423
423
.. productionlist :: python-grammar
424
424
yield_atom: "(" `yield_expression ` ")"
425
425
yield_from: "yield" "from" `expression `
426
- yield_expression: "yield" `expression_list ` | `yield_from `
426
+ yield_expression: "yield" `yield_list ` | `yield_from `
427
427
428
428
The yield expression is used when defining a :term: `generator ` function
429
429
or an :term: `asynchronous generator ` function and
@@ -454,9 +454,9 @@ When a generator function is called, it returns an iterator known as a
454
454
generator. That generator then controls the execution of the generator
455
455
function. The execution starts when one of the generator's methods is called.
456
456
At that time, the execution proceeds to the first yield expression, where it is
457
- suspended again, returning the value of :token: ` ~python-grammar:expression_list `
458
- to the generator's caller,
459
- or ``None `` if :token: `~python-grammar:expression_list ` is omitted.
457
+ suspended again, returning the value of
458
+ :token: ` ~python-grammar:flexible_expression_list ` to the generator's caller,
459
+ or ``None `` if :token: `~python-grammar:flexible_expression_list ` is omitted.
460
460
By suspended, we mean that all local state is
461
461
retained, including the current bindings of local variables, the instruction
462
462
pointer, the internal evaluation stack, and the state of any exception handling.
@@ -545,9 +545,9 @@ is already executing raises a :exc:`ValueError` exception.
545
545
:meth: `~generator.__next__ ` method, the current yield expression always
546
546
evaluates to :const: `None `. The execution then continues to the next yield
547
547
expression, where the generator is suspended again, and the value of the
548
- :token: `~python-grammar:expression_list ` is returned to :meth: ` __next__ `'s
549
- caller. If the generator exits without yielding another value, a
550
- :exc: `StopIteration ` exception is raised.
548
+ :token: `~python-grammar:flexible_expression_list ` is returned to
549
+ :meth: ` __next__ `'s caller. If the generator exits without yielding another
550
+ value, a :exc: `StopIteration ` exception is raised.
551
551
552
552
This method is normally called implicitly, e.g. by a :keyword: `for ` loop, or
553
553
by the built-in :func: `next ` function.
@@ -664,17 +664,17 @@ how a generator object would be used in a :keyword:`for` statement.
664
664
Calling one of the asynchronous generator's methods returns an :term: `awaitable `
665
665
object, and the execution starts when this object is awaited on. At that time,
666
666
the execution proceeds to the first yield expression, where it is suspended
667
- again, returning the value of :token: `~python-grammar:expression_list ` to the
668
- awaiting coroutine. As with a generator, suspension means that all local state
669
- is retained, including the current bindings of local variables, the instruction
670
- pointer, the internal evaluation stack, and the state of any exception handling.
671
- When the execution is resumed by awaiting on the next object returned by the
672
- asynchronous generator's methods, the function can proceed exactly as if the
673
- yield expression were just another external call. The value of the yield
674
- expression after resuming depends on the method which resumed the execution. If
675
- :meth: `~agen.__anext__ ` is used then the result is :const: `None `. Otherwise, if
676
- :meth: `~agen.asend ` is used, then the result will be the value passed in to that
677
- method.
667
+ again, returning the value of :token: `~python-grammar:flexible_expression_list `
668
+ to the awaiting coroutine. As with a generator, suspension means that all local
669
+ state is retained, including the current bindings of local variables, the
670
+ instruction pointer, the internal evaluation stack, and the state of any
671
+ exception handling. When the execution is resumed by awaiting on the next object
672
+ returned by the asynchronous generator's methods, the function can proceed
673
+ exactly as if the yield expression were just another external call. The value of
674
+ the yield expression after resuming depends on the method which resumed the
675
+ execution. If :meth: `~agen.__anext__ ` is used then the result is :const: `None `.
676
+ Otherwise, if :meth: `~agen.asend ` is used, then the result will be the value
677
+ passed in to that method.
678
678
679
679
If an asynchronous generator happens to exit early by :keyword: `break `, the caller
680
680
task being cancelled, or other exceptions, the generator's async cleanup code
@@ -728,10 +728,10 @@ which are used to control the execution of a generator function.
728
728
asynchronous generator function is resumed with an :meth: `~agen.__anext__ `
729
729
method, the current yield expression always evaluates to :const: `None ` in the
730
730
returned awaitable, which when run will continue to the next yield
731
- expression. The value of the :token: `~python-grammar:expression_list ` of the
732
- yield expression is the value of the :exc: `StopIteration ` exception raised by
733
- the completing coroutine. If the asynchronous generator exits without
734
- yielding another value, the awaitable instead raises a
731
+ expression. The value of the :token: `~python-grammar:flexible_expression_list `
732
+ of the yield expression is the value of the :exc: `StopIteration ` exception
733
+ raised by the completing coroutine. If the asynchronous generator exits
734
+ without yielding another value, the awaitable instead raises a
735
735
:exc: `StopAsyncIteration ` exception, signalling that the asynchronous
736
736
iteration has completed.
737
737
@@ -861,7 +861,7 @@ will generally select an element from the container. The subscription of a
861
861
:ref: `GenericAlias <types-genericalias >` object.
862
862
863
863
.. productionlist :: python-grammar
864
- subscription: `primary ` "[" `expression_list ` "]"
864
+ subscription: `primary ` "[" `flexible_expression_list ` "]"
865
865
866
866
When an object is subscripted, the interpreter will evaluate the primary and
867
867
the expression list.
@@ -1878,10 +1878,12 @@ Expression lists
1878
1878
single: , (comma); expression list
1879
1879
1880
1880
.. productionlist :: python-grammar
1881
- expression_list: `starred_expression ` ("," `starred_expression `)* [","]
1882
- starred_list: `starred_item ` ("," `starred_item `)* [","]
1883
- starred_expression: `expression ` | (`starred_item ` ",")* [`starred_item `]
1884
- starred_item: `assignment_expression ` | "*" `or_expr `
1881
+
1882
+ starred_item: "*" `or_expr `
1883
+ flexible_expression: `expression ` | `assignment_expression ` | `starred_item `
1884
+ flexible_expression_list: `flexible_expression ` ("," `flexible_expression `)* [","]
1885
+ yield_list: `expression ` ["," `flexible_expression_list `]
1886
+ | `starred_item` "," [`flexible_expression_list`]
1885
1887
1886
1888
.. index :: pair: object; tuple
1887
1889
0 commit comments