[Cython] Virtual cpdef methods

Jeroen Demeyer jdemeyer at cage.ugent.be
Tue Jun 21 07:35:33 EDT 2016


On 2016-06-21 08:17, Jeroen Demeyer wrote:
> But hang on, are you sure that this works? The C functions for cdef and
> cpdef functions have a different signature: cpdef functions have a
> __pyx_skip_dispatch argument while cdef functions don't have such an
> argument.

Answering my own question, it seems that Cython uses different vtab 
entries for the cdef and cpdef functions, where the cdef one calls the 
cpdef one with __pyx_skip_dispatch=0.

The only difference with my proposal is that the cdef method cannot 
automatically be overridden by a def method. But that can be solved by

cdef class MyClass(object):
     cdef foo(self):
         return (<object>self).foo()

So this overriding of cdef methods by cpdef methods might completely 
solve my use case. Thanks!


More information about the cython-devel mailing list