I have a python class which has a few properties. I converted the class to a cython extension type and defined the properties within it, using the cython syntax for properties http://docs.cython.org/src/userguide/extension_types.html#properties. I see that properties have to be declared using def or I get a compile error “cdef statement not allowed here”.
My class is also used within another cython module and I’d like to access properties from the class at c speed rather than python speed, otherwise it negates a bit the speedup I gain by using cython. I know it would be faster if I use cdef setter and getter functions like get_params() and set_params(params) but if I do this change, then I would have to do it too in the python code (so that my python and cython code don’t differ too much and can be compatible) but that makes the python code less readable…. dilemma!
is there a fast way to access properties in cython? or do you have any other suggestions so that I don’t have to change my python code to use setter and getter functions too?
Not really, since descriptors only exist at the Python level. Have your Cython code implement getters and setters, and create a Python type that exposes them via properties.