
On 9/15/2021 12:33 AM, Guido van Rossum wrote:
On Tue, Sep 14, 2021 at 9:03 PM Steven D'Aprano <steve@pearwood.info <mailto:steve@pearwood.info>> wrote:
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 <https://docs.python.org/3/library/stdtypes.html#iterator-types>
Like Steven, I consider 'iterators are iterables' to be a very positive feature.
Huh, so it does. And in very clear words as well. I still don't think this should be enforced by checks for the presence of __iter__ in situations where it's not going to be called (e.g. in iter() itself and in "for x in it").
I agree with this also as I consider 'duck typing' (delayed type checking by use) and 'consenting adults' (break rules at one's own risk) to also be features. If iter were to check for __iter__ on the return object, it might as well call it to see if it returns the same object. That might be appropriate for a 'SargentPython' implementation, but, to me, not for CPython. -- Terry Jan Reedy