[Python-ideas] Yield-From: Finalization guarantees

Guido van Rossum guido at python.org
Thu Mar 26 04:56:46 CET 2009

On Mon, Mar 23, 2009 at 4:24 PM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> We have a decision to make. It appears we can have
> *one* of the following, but not both:
> (1) In non-refcounting implementations, subiterators
> are finalized promptly when the delegating generator
> is explicitly closed.
> (2) Subiterators are not prematurely finalized when
> other references to them exist.
> Since in the majority of intended use cases the
> subiterator won't be shared, (1) seems like the more
> important guarantee to uphold. Does anyone disagree
> with that?
> Guido, what do you think?

Gee, I'm actually glad I waited a while, because the following
discussion shows that this is a really hairy issue... I think (1)
means propagating GeneratorExit into the subgenerator (and recursively
if that's also waiting in a yield-from), while (2) would mean not
propagating it, right? I agree that (1) seems to make more sense
unless you can think of a use case for (2) -- and it seems from Nick's
last post that such a use case would have to be rather horrendously

--Guido van Rossum (home page: http://www.python.org/~guido/)

More information about the Python-ideas mailing list