Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2f825af

Browse files
committed
Issue22988: clarify yield and exception blocks
1 parent 845d33c commit 2f825af

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

Doc/reference/expressions.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,9 @@ The execution starts when one of the generator's methods is called. At that
330330
time, the execution proceeds to the first yield expression, where it is
331331
suspended again, returning the value of :token:`expression_list` to the generator's
332332
caller. By suspended, we mean that all local state is retained, including the
333-
current bindings of local variables, the instruction pointer, and the internal
334-
evaluation stack. When the execution is resumed by calling one of the
333+
current bindings of local variables, the instruction pointer, the internal
334+
evaluation stack, and the state of any exception handling. When the execution
335+
is resumed by calling one of the
335336
generator's methods, the function can proceed exactly as if the yield expression
336337
were just another external call. The value of the yield expression after
337338
resuming depends on the method which resumed the execution. If
@@ -348,8 +349,8 @@ suspended. The only difference is that a generator function cannot control
348349
where the execution should continue after it yields; the control is always
349350
transferred to the generator's caller.
350351

351-
Yield expressions are allowed in the :keyword:`try` clause of a :keyword:`try`
352-
... :keyword:`finally` construct. If the generator is not resumed before it is
352+
Yield expressions are allowed anywhere in a :keyword:`try` construct. If the
353+
generator is not resumed before it is
353354
finalized (by reaching a zero reference count or by being garbage collected),
354355
the generator-iterator's :meth:`~generator.close` method will be called,
355356
allowing any pending :keyword:`finally` clauses to execute.

0 commit comments

Comments
 (0)