[Python-ideas] Yield-From: Finalization guarantees

Greg Ewing greg.ewing at canterbury.ac.nz
Fri Mar 27 06:01:08 CET 2009


Nick Coghlan wrote:

> That makes perfect sense to me as a justification for treating
> GeneratorExit the same as any other exception (i.e. delegating it to the
> subgenerator). It doesn't lead me to think that the semantics ever need
> to involve calling close().

I'm also treating close() and throw(GeneratorExit) on
the delegating generator as equivalent for finalization
purposes. So if throw(GeneratorExit) doesn't fall back
to close() on the subiterator, closing the delegating
generator won't finalize the subiterator unless it
pretends to be a generator by implementing throw().

Since the inlining principle strictly only applies to
subgenerators, it doesn't *require* this behaviour,
but to my mind it strongly suggests it.

-- 
Greg



More information about the Python-ideas mailing list