Search code examples
pythoncnumpypython-c-api

How to check if PyObject* points to the type numpy.uint8


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.)


Solution

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