Is 'x' an instance of a new-style class?

Gabriel Genellina gagsl-py2 at
Tue Sep 16 11:38:33 CEST 2008

En Tue, 16 Sep 2008 05:26:14 -0300, MatthewS < at>  

> I've seen the question raised several times here, but apparently never
> answered. Since PyInstance_Check returns False for new-style class
> instances, is there a standard procedure for testing this using the C-
> Api?
> I would greatly appreciate some help with this.

In Python you would write isinstance(x, object). In C, "object" is  
PyBaseObject_Type, and a direct translation would be  
PyObject_IsInstance(x, PyBaseObject_Type), or perhaps  
PyObject_TypeCheck(x,  &PyBaseObject_Type) (to mimic how other PyXXX_Check  
are implemented, and probably faster)

Gabriel Genellina

More information about the Python-list mailing list