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

Erik Groeneveld erik at cq2.org
Thu Apr 23 13:31:36 CEST 2009


2009/4/23 Jacob Holm <jh at improva.dk>:

>>      "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:
>
>   generator.close()
>   raise GeneratorExit
>
> instead?
>
> 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.

These two line were exactly what I started out with, but I see that
expanded it because I had a different interpretation of the PEP.  I
interpreted it as when the generator did not raise an exception, but
close does, it is a different situation.  I'll think about it more
deeply. Thanks btw!

Erik


>
> HTH
> -Jacob
>



More information about the Python-ideas mailing list