Closed
Description
Bug report
Bug description:
Defining an interator for a class in a separate class no longer works properly in 3.13. With the following test_iter.py
:
class list2(list):
def __iter__(self):
return list2iterator(self)
class list2iterator:
def __init__(self, X):
self._X = X
self._pointer = -1
def __next__(self):
self._pointer += 1
if self._pointer == len(self._X):
self._pointer = -1
raise StopIteration
return self._X[self._pointer]
With Python 3.13.1 one gets:
>>> from test_iter import list2
>>> X=list2([1,2,3])
>>> [x for x in X]
Traceback (most recent call last):
File "<python-input-2>", line 1, in <module>
[x for x in X]
^
TypeError: 'list2iterator' object is not iterable
With Python 3.12.7 it works:
>>> from test_iter import list2
>>> X=list2([1,2,3])
>>> [x for x in X]
[1, 2, 3]
Bisected to bcc7227e
CPython versions tested on:
3.12, 3.13
Operating systems tested on:
Linux