[Python-ideas] Revised**12 PEP on Yield-From

Jacob Holm jh at improva.dk
Thu Apr 23 12:34:48 CEST 2009

Hi Erik

Erik Groeneveld wrote:
> There is one problem left however.  The code dealing with
> GeneratorExit has to undo the work of close() a bit.  To account for:
>       "If this call results in an exception, it is propagated to the delegating
>       generator. Otherwise, GeneratorExit is raised in the delegating
> generator."
> and knowing that close() raises a RuntimeError when a generator
> ignores GeneratorExit, I have:
>                     try:
>                         generator.close()
>                     except RuntimeError:
>                         pass
>                     raise GeneratorExit
> But this code cannot tell if the generator intended to raise a
> RuntimeError. 

Why do you think you can't just do:

    raise GeneratorExit


This does excatly what the quote says, and if you look at the expansion 
in the PEP that is exactly how it is defined there.


More information about the Python-ideas mailing list