Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cython inheritance

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 855
Elena Mazzi Avatar asked Oct 04 '11 17:10

Elena Mazzi


People also ask

Is Cython object oriented?

[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.

Is Cython compiled?

Cython is a compiled language that is typically used to generate CPython extension modules.

What is Cython extension?

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.

What is Cimport?

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.


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 140
Niklas R Avatar answered Sep 28 '22 07:09

Niklas R