[Python-ideas] Yield-From: Handling of GeneratorExit
Greg Ewing
greg.ewing at canterbury.ac.nz
Fri Apr 3 03:51:18 CEST 2009
Bruce Frederiksen wrote:
> If you re-define close to return the value attached to StopIteration,
There may be a misconception here. I haven't been
intending for close() to return the return value.
That's not necessary to support Jacob's desire for
the subgenerator to be able to return a value
while the outer generator is being closed.
That's because the subgenerator would *not* have
its close() method called -- rather, GeneratorExit
would be thrown into it. If it returned, this would
manifest as a GeneratorReturn which could be caught
and treated accordingly.
I wouldn't necessarily be against having close()
return the value from GeneratorReturn, but that's
a separate issue to be decided independently.
--
Greg
More information about the Python-ideas
mailing list