Hello,
I recently learned from Robert Bradshaw that it is legal in Cython to
override cdef methods by cpdef methods. But doing this in a .pxd file
causes a compile-time error:
*foo.pyx*:
cdef class Base(object):
cdef meth(self):
print("Base.meth()")
cdef class Derived(Base):
cpdef meth(self):
print("Derived.meth()")
*foo.pxd*:
cdef class Base(object):
cdef meth(self)
cdef class Derived(Base):
cpdef meth(self)
This gives (both on 0.24.1 and on master):
Error compiling Cython file:
------------------------------------------------------------
...
cdef class Base(object):
cdef meth(self):
return self
cdef class Derived(Base):
cpdef meth(self):
^
------------------------------------------------------------
foo.pyx:6:10: 'meth' already defined
As second attempt, I could simply not declare the cpdef method in the
.pxd file. Just use
cdef class Derived(Base):
pass
This compiles, but leads to bugs with broken vtabs. I am omitting the
complete code here, but it's clear why this cannot work: other modules
get the vtab wrong since they don't know about the cpdef slot.
Jeroen.
_______________________________________________
cython-devel mailing list
cython-devel@python.org
https://mail.python.org/mailman/listinfo/cython-devel