PyDict_Contains is recursive
For the following Cython code (which can be compiled with pypy cythonize.py -if filename
)
class C(dict):
def __contains__(self, key):
print("C.__contains__")
return dict.__contains__(self, key)
1 in C()
Cython converts dict.__contains__
to PyDict_Contains
. PyPy's implementation of PyDict_Contains
(https://foss.heptapod.net/pypy/pypy/-/blob/branch/default/pypy/module/cpyext/dictobject.py#L147) looks to just lookup __contains__
on the object and call it, thus causing an infinite loop.