[docs] [issue22988] No error when yielding from `finally`

Ethan Furman report at bugs.python.org
Wed Dec 3 20:05:41 CET 2014


Ethan Furman added the comment:

Here's the excerpt from the docs:
--------------------------------
> Yield expressions are allowed in the try clause of a try ... finally construct.
> If the generator is not resumed before it is finalized (by reaching a zero reference
> count or by being garbage collected), the generator-iterator’s close() method will be
> called, allowing any pending finally clauses to execute.

This certainly makes it sound like 'yield' is okay in the 'try' portion, but not the 'finally' portion.

So 'yield' is allowed in the 'try' portion, and it's allowed in the 'finally' portion -- is it also allowed in the 'except' portion?  If so, we could simplify the first line to:

> Yield expressions are allowed in try ... except ... finally constructs.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22988>
_______________________________________


More information about the docs mailing list