When playing with cdef classes, access to attributes is compiled to access members of the C-structure. As a result, to access the cdef element of object A you must be sure of type A In __cinit__ you did not tell Keaton that there was another instance of StructName . Therefore, Cython refuses to compile other.__structname . To fix the problem, just write
def __cinit__(self, StructName other = None):
Note: None equivalent to NULL and therefore is accepted as StructName .
If you want more polymorphism, then you need to rely on cast types:
def __cinit__(self, other = None): cdef StructName ostr if not other: self.__structname = c_libname.constructStructName() elif type(other) is StructName: ostr = <StructName> other self.__structname = ostr.__structname
hivert
source share