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.
[Cython] is a programming language that makes writing C extensions for the Python language as easy as Python itself. It aims to become a superset of the [Python] language which gives it high-level, object-oriented, functional, and dynamic programming.
Cython is a compiled language that is typically used to generate CPython extension modules.
Cython is an optimising static compiler for both the Python programming language and the extended Cython programming language (based on Pyrex). It makes writing C extensions for Python as easy as Python itself. Cython gives you the combined power of Python and C to let you.
The cimport mechanism provides a clean and simple way to solve the problem of wrapping external C functions with Python functions of the same name. All you need to do is put the extern C declarations into a .pxd file for an imaginary module, and cimport that module.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With