On Sun, Sep 19, 2021 at 8:15 AM Steve Holden <steve@holdenweb.com> wrote:
I understood that _iterables_ are required to have an __iter__ method, not iterators.
Therefore, are we simply discussing whether all iterators should be iterable?
At this point it's more about how to document this.
At the moment the CPython implementation does't require that AFAIK.
Correct. I plan to go through the docs and clarify things. I opened https://bugs.python.org/issue45250 to track this.
regards Steve
On Tue, Sep 14, 2021 at 8:39 PM Guido van Rossum <guido@python.org> 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.
On Tue, Sep 14, 2021 at 12:30 PM Brett Cannon <brett@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-leave@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/3W7TDX5K... 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-c...> _______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-leave@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/OICGRBPL... Code of Conduct: http://python.org/psf/codeofconduct/
_______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-leave@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/KHDMNMW6... Code of Conduct: http://python.org/psf/codeofconduct/