Domanda

I'm trying to change the method signature of a cpdef method in a derived class but keep getting errors.

In *.pxd:

from libc.stdint cimport uint64_t

cdef struct _ft_device_list_info_node_os:
        uint64_t ftHandle
ctypedef _ft_device_list_info_node_os FT_DEVICE_LIST_INFO_NODE_OS

cdef class BaseClass(object):
    cpdef object do_something(BaseClass self)

cdef class DerivedClass(BaseClass):
    cdef FT_DEVICE_LIST_INFO_NODE_OS cheese

In *.pyx:

cdef class BaseClass(object):

    cpdef object do_something(BaseClass self):
        pass

cdef class DerivedClass(BaseClass):

    cpdef object do_something(DerivedClass self, int val=10):
        cdef FT_DEVICE_LIST_INFO_NODE_OS node
        self.cheese = node

When compiling I get the following error:

cythoning test.pyx to pybarst\test.cpp

Error compiling Cython file:
------------------------------------------------------------
...

cdef class DerivedClass(BaseClass):

    cpdef object do_something(DerivedClass self, int val=10):
        cdef FT_DEVICE_LIST_INFO_NODE_OS node
        self.cheese = node
                         ^
------------------------------------------------------------

test.pyx:10:26: Cannot convert 'FT_DEVICE_LIST_INFO_NODE_OS' to Python object

This error doesn't seem to happen if the struct is defined with only ints or simpler data types, i.e. if I do int ftHandle the error does not occur.

It seems that it gets confused in the derived class's do_something method, where it thinks that it is the base class and therefore cannot find cheese.

Is there maybe a proper way of adding parameters in a derived class.

È stato utile?

Soluzione

Turns out it was a bug that they fixed with this. See here.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top