Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can I not derive a Cython cdef extension type from another? [duplicate]

I have a A.pxd (with just declaration of functions) and A.pyx that contains just a class A with all the function body.

Than I have B that inherits from A,

and for B I have B.pxd with some functions

B.pyx

class Bclass(A):
    #all the funcions body

I want to now how to tell to B.pyx to ricognise A as a type name?

what i do is:

B.pyx

cimport A
import A
from A import Aclass
cdef Bclass(Aclass):
   #body

but it says me: A is not a type name

If i do this in just one file.pyx it works without problems but working with files.pxd it does not go.

like image 398
Elena Mazzi Avatar asked Dec 05 '25 04:12

Elena Mazzi


1 Answers

Use

from A cimport Aclass
cdef class Bclass(Aclass):
    # ...

or

cimport A
cdef class Bclass(A.Aclass):
    # ...

Note that Aclass must be cdef'fed class, Cython extension types cannot inherit from Python classes.

like image 152
Niklas R Avatar answered Dec 08 '25 10:12

Niklas R



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!