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. On Tue, Sep 14, 2021 at 12:30 PM Brett Cannon <br...@python.org> wrote: > Over in https://github.com/python/typeshed/issues/6030 I have managed to > kick up a discussion over what exactly an "iterator" is. If you look at > https://docs.python.org/3/library/functions.html#iter you will see the > docs say it "Return[s] an iterator > <https://docs.python.org/3/glossary.html#term-iterator> object." Great, > but you go the glossary definition of "iterator" at > https://docs.python.org/3/glossary.html#term-iterator you will see it > says "[i]terators are required to have an __iter__() > <https://docs.python.org/3/reference/datamodel.html#object.__iter__> > method" which neither `for` nor `iter()` actually enforce. > > Is there something to do here? Do we loosen the definition of "iterator" > to say they *should* define __iter__? Leave it as-is with an > understanding that we know that it's technically inaccurate for iter() but > that we want to encourage people to define __iter__? I'm assuming people > don't want to change `for` and `iter()` to start requiring __iter__ be > defined if we decided to go down the "remove the __aiter__ requirement" > from aiter() last week. > > BTW all of this applies to async iterators as well. > _______________________________________________ > 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/3W7TDX5KNVQVGT5CUHBK33M7VNTP25DZ/ > Code of Conduct: http://python.org/psf/codeofconduct/ > -- --Guido van Rossum (python.org/~guido) *Pronouns: he/him **(why is my pronoun here?)* <http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/>
_______________________________________________ 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/OICGRBPLXO6WXO4CHTGUK46WIHO7PDUU/ Code of Conduct: http://python.org/psf/codeofconduct/