0

I have a class in a pyx file:

cdef class Qos:

    cdef object _policies

    def __cinit__(self, policies=[]):
        self._c_qos = dds.dds_qos_create()

    def set_policies(self, policies):
        self._policies[p.id] = p

When I am importing the compiled *.pyd file I can see the class Qos.

This works:

from dds import Qos
print(dir(Qos))

I read that cdefed objects are not visible from Python, why can I see `Qos?

What I would really like to do is to access the also cdefed attribute Qos._c_qos or Qos._policies from instances of Qos, but they are not available.

Is there a difference between these cdefs? Is there a setting on which cdefs are exposed and which are not?

Joe
  • 6,758
  • 2
  • 26
  • 47
  • Part of your question is answered in https://stackoverflow.com/questions/55230665/cython-class-attributeerror/55231514#55231514. The other part is just realising that a `cdef class` is different from `cdef typename variable_name`. – DavidW Feb 22 '20 at 19:32
  • Do you mean that "cdef classes are extension types" as the doc mentions [here](https://cython.readthedocs.io/en/latest/src/tutorial/cdef_classes.html)? – Joe Feb 22 '20 at 21:06
  • Yes. `cdef class` defines an extension type which is visible from Python. It's a little inconsistent since most other uses for `cdef` make something not visible from Python. But it's more just realising that `cdef` means multiple (similar) things, and they are a bit inconsistent in places. – DavidW Feb 22 '20 at 21:40

0 Answers0