Describe the bug
It's possible to get an infinite loop for an add (and presumably other operators) operator that returns NotImplemented when used with a derived class.
To Reproduce
cdef class Base:
def __add__(self, other):
return NotImplemented
class Derived(Base):
pass
and to test:
>>> import hmmm
>>> x = hmmm.Base()
>>> y = hmmm.Derived()
>>> y+x # works OK as expected
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'Derived' and 'hmmm.Base'
>>> x+y
For x+y I get an infinite loop but Pandas reports segmentation fault - probably just to do with tail-call recursion optimization or not.
Expected behavior
Should just be NotImplementedError
Environment (please complete the following information):
- OS: Linux
- Python version 3.8.9
- Cython version 0e80efb (close to current master)
Additional context
I think this is to do with the changes to support __radd__ etc.. I think it's somewhere in:
|
static PyObject *{{func_name}}(PyObject *left, PyObject *right {{extra_arg_decl}}) { |
However, I haven't traced the error through in great detail so not 100% sure exactly what's gone wrong.
Describe the bug
It's possible to get an infinite loop for an add (and presumably other operators) operator that returns
NotImplementedwhen used with a derived class.To Reproduce
and to test:
For
x+yI get an infinite loop but Pandas reports segmentation fault - probably just to do with tail-call recursion optimization or not.Expected behavior
Should just be
NotImplementedErrorEnvironment (please complete the following information):
Additional context
I think this is to do with the changes to support
__radd__etc.. I think it's somewhere in:cython/Cython/Utility/ExtensionTypes.c
Line 383 in 034fc26
However, I haven't traced the error through in great detail so not 100% sure exactly what's gone wrong.