[Python-ideas] Generators are iterators

Alexander Belopolsky alexander.belopolsky at gmail.com
Wed Dec 10 23:11:43 CET 2014

On Wed, Dec 10, 2014 at 4:34 PM, Greg Ewing <greg.ewing at canterbury.ac.nz>

> Chris Angelico wrote:
>> """
>> 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.
>> """
> No, that's still too confused

I think the problem is with the term "generator function" because what we
call "generator function" is neither a generator nor a function.  It is a
callable that returns a generator.   To our excuse, this abuse of language
is not uncommon.  People often say "integer function" when they mean a
function with integer domain and range (or even just range).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20141210/b80c3714/attachment.html>

More information about the Python-ideas mailing list