I am working on wrapping a C library using cython. I would like to use a cdef class
to wrap a simple struct. The struct does require some parameters to be properly initialized. I put the corresponding code int the __cinit__
method like so:
cdef class Func:
cdef library.Func* func
def __cinit__(self, int value):
library.init_func(&self.func, value)
In python code I can create a function object via f = Func(17)
. The code then handles the initialization just fine. My question is the following: Say I want to extend the Func
class in python (class MyFunc(Func): ...
). How do I add a constructor to to MyFunc
?
I would like to write a constructor with other parameters which calls
__cinit__(self, int value)
with a value derived from constructor parameters. But it does not seem to be possible (likely for good reason) to call __cinit__
from python code.
Is there some way to include constructors in subclasses or should I create a wrapper around the function and delegate methods / properties?