[Python-ideas] Generators are iterators

Guido van Rossum guido at python.org
Wed Dec 10 21:46:11 CET 2014

I have replaced the confusing paragraph with this:

The proposal does not change the relationship between generators and
iterators: a generator object is still an iterator, and not all
iterators are generators.  Generators have additional methods that
iterators don't have, like ``send`` and ``throw``.  All this is
unchanged.  Nothing changes for generator users -- only authors of
generator functions may have to learn something new.

Let us know if there is still confusion about what the PEP means.


On Wed, Dec 10, 2014 at 10:13 AM, Guido van Rossum <guido at python.org> wrote:

> Everyone (including Chris), hold your horses. I will come up with better
> words for the PEP. I apologize for the confusion.
> On Wed, Dec 10, 2014 at 9:37 AM, Nathaniel Smith <njs at pobox.com> wrote:
>> On 10 Dec 2014 16:38, "Chris Angelico" <rosuav at gmail.com> wrote:
>> >
>> > Would it be better to clarify that as "generator functions"? Maybe
>> > something like this:
>> >
>> > """
>> > Under this proposal, generator functions and iterators would be
>> > distinct, but related, concepts.  Like the mixing of text and bytes in
>> > Python 2, the mixing of generators and iterators has resulted in
>> > certain perceived conveniences, but proper separation will make bugs
>> > more visible. The distinction is simple: A generator function returns
>> > a generator object. The latter is an iterator, having proper __iter__
>> > and __next__ methods, while the former has neither and does not follow
>> > iterator protocol.
>> > """
>> I find this more confusing than the original, actually, because now it
>> sounds like you're saying that the distinction between a generator function
>> and a generator instance is something new that this PEP is adding, in order
>> to fix all the problems that are being caused by people writing 'for x in
>> genfunc: ...'. Which doesn't make much sense. Like Nick said, it seems to
>> me that the key distinction to emphasize is the distinction between
>> generator function bodies and __next__ method bodies.
>> -n
>> _______________________________________________
>> Python-ideas mailing list
>> Python-ideas at python.org
>> https://mail.python.org/mailman/listinfo/python-ideas
>> Code of Conduct: http://python.org/psf/codeofconduct/
> --
> --Guido van Rossum (python.org/~guido)

--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20141210/a317a1a3/attachment.html>

More information about the Python-ideas mailing list