Domanda

I'm having some trouble with this piece of code running under Cython 2.0:

cdef class Foo(object):
  cpdef twerk(self): #using def instead does not help
    print "Bustin' some awkward moves."

cdef class ShyFoo(Foo):
  cpdef twerk(self):
    print "Do I really have to?"
    super(self, ShyFoo).twerk()
    print "I hate you so much."

ShyFoo().twerk()

RuntimeError: maximum recursion depth exceeded while calling a Python object

However, removing cdefs and replacing cpdefs with defs gets me working Python.

The backtrack looks like this:

File "mytest.pyx", line 61, in mytest.Foo.twerk
  cpdef twerk(self):
File "mytest.pyx", line 67, in mytest.ShyFoo.twerk
  super(ShyFoo, self).twerk()
File "mytest.pyx", line 61, in mytest.Foo.twerk
  cpdef twerk(self):
File "mytest.pyx", line 67, in mytest.ShyFoo.twerk
    super(ShyFoo, self).twerk()
....................................................

What am I doing wrong? I have found this relevant ticket from 4 years ago, but I guess it got no attention because of an user error.

È stato utile?

Soluzione

It seems like the bug you linked to in your question is the problem. If you change both methods to def instead of cpdef, it works fine. Alternatively, you can remove the call to super like this:

cdef class Foo(object):
    cpdef twerk(self):
        print "Bustin' some awkward moves."

cdef class ShyFoo(Foo):
    cpdef twerk(self):
        print "Do I really have to?"
        Foo.twerk(self)
        print "I hate you so much."

ShyFoo().twerk()
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top