If it helps, I have tons of code that tests for iterators using:

    iter(obj) is obj

That has been a documented requirement for the iterator protocol 
forever. Its in the PEP.

"A class that wants to be an iterator should implement two methods: a 
next() method that behaves as described above, and an __iter__() method 
that returns self."

https://www.python.org/dev/peps/pep-0234/

We have objects such that:

    iter(obj)

returns an iterator, but aren't themselves iterators. The most common 
example of that would be, I think, classes that define __iter__ as a 
generator method:

    class A:
        def __iter__(self):
            for x in range(10):
                yield x

Then we have actual iterators, like iter(A()). They define `__iter__` 
that returns self.

I don't know what I would call an object that only has __next__, 
apart from "broken" :-(


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

Reply via email to