[Python-ideas] Yield-From: Handling of GeneratorExit

Bruce Frederiksen dangyogi at gmail.com
Thu Apr 2 16:57:16 CEST 2009


Jacob Holm wrote:
> I think it would be better not to loop, still return the final value 
> from close, and still just throw GeneratorExit to subiterators without 
> trying to reraise.
This sounds better to me too, except for the last part -- not reraising 
GeneratorExit.

If you re-define close to return the value attached to StopIteration, 
then I think that it makes sense to define it to continue to return this 
value on subsequent calls to close.  This provides a way to still 
retrieve the returned value after the generator has been finalized in 
some other way.

And then, wouldn't this allow you to discard the StopIteration in yield 
from and reraise GeneratorExit to finalize the outer generator; but 
leaving it the option to call close itself on the inner generator to 
retrieve the return value, if it still wants it?

-bruce frederiksen



More information about the Python-ideas mailing list