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

Alexander Belopolsky alexander.belopolsky at gmail.com
Tue Nov 25 00:20:11 CET 2014


On Mon, Nov 24, 2014 at 5:48 PM, Chris Angelico <rosuav at gmail.com> wrote:
>
> As Guido said, "generator" is ambiguous; though I was
> inaccurate as well. A generator *object* is, as you show above, an
> iterator; a generator *function* is not actually iterable, but it is
> an iterator factory. An iterator class is also an iterator factory.


This is correct, and I don't think there is any ambiguity:

>>> def g(): yield 42
...
>>> type(g)
<class 'function'>
>>> type(g())
<class 'generator'>

As explained in PEP 255, "a Python generator is a kind of Python
iterator[1], but of an especially powerful kind."  The other term
introduced by PEP 255 is "generator function": "A function that contains a
yield statement is called a generator function."

In my view, PEP 479 naturally follows from careful reading of PEP 225.  All
one needs to understand is the difference between a function that returns
an iterator and its value.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20141124/aabc9e7f/attachment-0001.html>


More information about the Python-ideas mailing list