Extension type inheritance

41 views
Skip to first unread message

Nicolai Mikal Sætran

unread,
Jul 23, 2016, 5:45:25 PM7/23/16
to cython-users
Hi. I have a general question regarding inheritance with cython extension types.

A simple example would be:

--------------------------------------------------
cdef class my_ext:
cdef ...

def __cinit__(self,...):
...

cdef type foo(self, ...):
return ...

def bar(self, ...):
return self.foo(...)

cdef class my_other_ext(my_ext):
cdef type foo(self, ...):
return ...

--------------------------------------------------

In the base type, bar() calls foo() when called.

my_other_ext inherits from my_ext, and I want its cdef foo() method to override the foo() method of the base extension type so that bar() calls this new overriding method when itself is called. Only problem is that bar() continues to call the foo() method of my_ext and not the new overriding method.

Is this simply not possible in cython?

Robert Bradshaw

unread,
Jul 23, 2016, 8:01:17 PM7/23/16
to cython...@googlegroups.com
Cython does implement inheritance like this. Maybe you have a typo in
your code or something; the example above will call my_other_ext's
foo() when my_other_ext().bar() is called.

- Robert
Reply all
Reply to author
Forward
0 new messages