[Python-ideas] Yield-From: Finalization guarantees

Nick Coghlan ncoghlan at gmail.com
Thu Mar 26 07:32:28 CET 2009

Greg Ewing wrote:
> We might still want one special case. If GeneratorExit is thrown
> and the subiterator has no throw() or the GeneratorExit propagates
> back out of the throw(), I think an attempt should be made to
> close() it. Otherwise, explicitly closing the delegating generator
> wouldn't be guaranteed to finalize the subiterator unless it had
> a throw() method, whereas one would expect having close() to be
> sufficient for this.

I'm not so sure about that - we don't do it for normal iteration, so why
would we do it for the new expression?

However, I've been pondering the shareable iterator case a bit more, and
in trying to come up with even a toy example, I couldn't think of
anything that wouldn't be better handled just by actually *iterating*
over the shared iterator with a for loop.

Since the main advantage that the new expression has over simple
iteration is delegating send() and throw() correctly, and I'm suggesting
that shared iterators and those two methods don't mix, perhaps this
whole issue can be set aside?


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-ideas mailing list