PyPy3.8: __repr__ of namedtuple subclass with __iter__ (e.g. importlib.metadata.EntryPoint) causes infinite recursion
Trivial reproducer (based on reducing importlib.metadata.EntryPoint
):
import collections
class EntryPoint(
collections.namedtuple('EntryPointBase', 'name value group')):
def __iter__(self):
return iter((self.name, self))
print(repr(EntryPoint('a', 'b', 'c')))
$ python3.8 repro.py
EntryPoint(name='a', value='b', group='c')
$ pypy3 repro.py
Traceback (most recent call last):
File "repro.py", line 14, in <module>
print(repr(EntryPoint('a', 'b', 'c')))
File "/usr/lib/pypy3.8/collections/__init__.py", line 421, in __repr__
return self.__class__.__name__ + repr_fmt % self
File "/usr/lib/pypy3.8/collections/__init__.py", line 421, in __repr__
return self.__class__.__name__ + repr_fmt % self
File "/usr/lib/pypy3.8/collections/__init__.py", line 421, in __repr__
return self.__class__.__name__ + repr_fmt % self
[Previous line repeated 887 more times]
File "repro.py", line 11, in __iter__
return iter((self.name, self))
RecursionError: maximum recursion depth exceeded
It seems that for some reason this is using __iter__
on PyPy3.8 but not on CPython.