[Python-Dev] PEP 479: Change StopIteration handling inside generators

Isaac Schwabacher ischwabacher at wisc.edu
Tue Nov 25 19:12:17 CET 2014


On 11/25/14, Guido van Rossum  wrote:
> On Tue, Nov 25, 2014 at 9:49 AM, Chris Angelico <ischwabacher at wisc.edu <rosuav at gmail.com')" target="1">rosuav at gmail.com> wrote:
> 
> > On Wed, Nov 26, 2014 at 4:45 AM, Isaac Schwabacher
> > <python.org/~guido(javascript:main.compose('new', 't=ischwabacher at wisc.edu>> wrote:
> > > Yield can also raise StopIteration, if its thrown in. The current interaction of generator.throw(StopIteration) with yield from cant be emulated under the PEPs behavior, though its not clear that thats a problem.
> > 
> > Hrm. I have *absolutely* no idea when you would use that,

To close the innermost generator in a yield-from chain. No, I don't know why you'd want to do that, either.

> > and how
> > you'd go about reworking it to fit this proposal. Do you have any
> > example code (production or synthetic) which throws StopIteration into
> > a generator?

No.

> Sounds like a good one for the obfuscated Python contest. :-)

I'm just playing with my food now. :)

> Unless the generator has a try/except surrounding the yield point into which the exception is thrown, it will bubble right out, and PEP 479 will turn this into a RuntimeError. I'll clarify this in the PEP (even though it logically follows from the proposal) -- I don't think there's anything to worry about.
> 
> 
> 
> -- 
> --Guido van Rossum (<a href=))


More information about the Python-Dev mailing list