[Python-Dev] PEP 479: Change StopIteration handling inside generators
Guido van Rossum
guido at python.org
Tue Nov 25 19:26:24 CET 2014
On Tue, Nov 25, 2014 at 10:12 AM, Isaac Schwabacher <ischwabacher at wisc.edu>
wrote:
> 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.
For that purpose you should call the generator's close() method. This
throws a GeneratorExit into the generator to give the generator a chance of
cleanup (typically using try/finally). Various reasonable things happen if
the generator misbehaves at this point -- if you want to learn what, read
the code or experiment a bit on the command line (that's what I usually do).
--
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20141125/f20c41ae/attachment.html>
More information about the Python-Dev
mailing list