On Thu, 16 Sept 2021 at 01:30, Chris Barker via Python-Dev
<python-dev@python.org> wrote:
> """
>  "[i]terators are required to have an __iter__() method" which neither `for` 
> nor `iter()` actually enforce.
> """
>
> I'm confused -- as far as I can tell `for` does enforce this -- well, it 
> doesn't enforce it, but it does require it, which is the same thing, yes? But 
> does it need to?

for enforces that *iterables* have an __iter__ method, not
*iterators*. (for takes an iterable, not an iterator, and uses
__iter__ to *get* an iterator from it).

The debate here is (I think!) whether an *iterator* that is not also
an *iterable* is a valid iterator.

IMO it is valid (because that's what the definitions say, basically)
but it may not be *useful* in certain circumstances, and it definitely
may not be *expected* (because nearly all iterators are iterables).
"Broken" is a strong word to use, though, and that might be why the
debate is continuing this long...

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

Reply via email to