On 9/15/2021 12:33 AM, Guido van Rossum wrote:
On Tue, Sep 14, 2021 at 9:03 PM Steven D'Aprano <st...@pearwood.info <mailto:st...@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

_______________________________________________
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/DJPR23CY6N3GP6DDULPBMSHWH7JKWMFT/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to