0

How do I use the Python C-API to check if a PyObject* points to the type numpy.uint8 etc?

(Note that I want to check if the PyObject* points to the type numpy.uint8, not if it points to an instance of the type numpy.uint8.)

Johan Råde
  • 20,480
  • 21
  • 73
  • 110

1 Answers1

1

You can use PyType_IsSubtype(child, parent) to see if the child type inherits the parent, but it operates on PyTypeObject*, not PyObject*.

brennie
  • 543
  • 1
  • 3
  • 12
  • And how do I get the PyTypeObject* for numpy.uint8? – Johan Råde Jul 28 '11 at 05:00
  • 1
    If you have an instance of numpy.uint8, you can access it via `object->ob_type`, but other than that, I don't know. I imagine you could get the `numpy` module it from the globals dict (via `PyEval_GetGlobals()`) and then access `numpy.uint8` from there, but I'm not sure on the exact method. – brennie Jul 29 '11 at 05:13