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

Greg Ewing greg.ewing at canterbury.ac.nz
Thu Apr 2 13:28:22 CEST 2009


I've had another idea about this. Suppose the close()
method of a generator didn't complain about reaching
a yield after GeneratorExit is raised, but simply
raised it again, and continued doing so until either
a return occured or an exception propagated out.

Seems to me this couldn't do any harm to a well-
behaved generator, since it has to be prepared to
deal with a GeneratorExit arising from any of its
yield points.

Yield-from would then no longer have the potential
to create broken generators, we wouldn't have to treat
GeneratorExit differently from any other exception,
and Jacob could have his subgenerators that return
values when you close them.

-- 
Greg





More information about the Python-ideas mailing list