Open
Description
I wanted to check whether an object is of type array
and ended up doing this:
PyObject *exc = PyErr_GetRaisedException();
PyObject *module = PyType_GetModuleByDef(Py_TYPE(lhs), &arraymodule);
if (module == NULL) {
if (!PyErr_Occurred() || PyErr_ExceptionMatches(PyExc_TypeError)) {
/* lhs is not an array instance - ignore the TypeError (if any) */
PyErr_SetRaisedException(exc);
return 0;
}
else {
_PyErr_ChainExceptions1(exc);
return -1;
}
}
PyErr_SetRaisedException(exc);
return array_Check(lhs, get_array_state(module));