[Python-ideas] PEP on yield-from: throw example

Greg Ewing greg.ewing at canterbury.ac.nz
Mon Feb 16 10:29:24 CET 2009

George Sakkis wrote:

> For throw() however, I strongly disagree that
> a raise statement in a loop should implicitly call generator.throw(),
> regardless of what "for" syntax is used.

Just in case it's not clear, the behaviour being suggested
here is *not* part of my proposal. As far as yield-from is
concerned, propagation of exceptions into the subgenerator
would only occur when throw() was called on the generator
containing the yield-from, and then only when it's suspended
in the midst of it. Raise statements within the delegating
generator have nothing to do with the matter and aren't
affected at all.

Having some examples to look at is a good idea, but
Bruce seems to be going off on a tangent and making some
proposals of his own for enhancing the for-loop. I fear
that this will only confuse the discussion further.

Perhaps I should also point out that yield-from is *not*
intended to help things like itertools.chain manage the
cleanup of its generators, so examples involving things
with chain-like behaviour are probably not going to help
clarify what it *is* intended for.

It would be nice to have a language feature to help with
things like that, but I have no idea at the moment what
such a thing would be like.


More information about the Python-ideas mailing list