On Tue, Sep 14, 2021 at 12:33:32PM -0700, Guido van Rossum wrote:
> My view of this is:
> 
> A. It's not an iterator if it doesn't define `__next__`.
> 
> B. It is strongly recommended that iterators also define `__iter__`.
> 
> In "standards" language, I think (A) is MUST and (B) is merely OUGHT or
> maybe SHOULD.

That's not what the docs say :-)

https://docs.python.org/3/library/stdtypes.html#iterator-types

Part of the problem is that there are two kinds of thing that we call 
"iterator":

1. Objects that we implicitly or explicitly pass to `iter()` in order to 
return an interator object; they only need to define an `__iter__` 
method that returns the actual iterator object itself.

(That's a slight simplification, because iter() will fall back on the 
Sequence Protocol if `__iter__` isn't defined. But to my mind, that 
makes Sequence Protocol objects *iterables* not iterators.)


2. Iterator objects themselves, which are defined by a protocol, not a 
type. The iterator object MUST define both `__iter__` and `__next__`, 
and the `__iter__` method MUST return self.


-- 
Steve
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/RBM2IBQUKA6NGYIEW4WQRQ2EJ3I4OZY2/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to