I'm trying to write a function to return the truth value of a given PyObject. This function should return the same value as the if() truth test -- empty lists and strings are False, etc. I have been looking at the python/include headers, but haven't found anything that seems to do this. The closest I came was PyObject_RichCompare() with True as the second value, but that returns False for "1" == True for example. Is there a convenient function to do this, or do I have to test against a sequence of types and do special-case tests for each possible type? What does the internal implementation of if() do?
Isn't this it, in object.h:
PyAPI_FUNC(int) PyObject_IsTrue(PyObject *);
?