TypeCheck vs IsInstance in C API

Kirk McDonald kirklin.mcdonald at gmail.com
Tue May 30 02:23:55 EDT 2006


I'm examining the C API, and I have a question.

http://docs.python.org/api/object.html

There are two functions that appear to do nearly same thing, and I just 
want to be certain I'm not missing something. First is PyObject_IsInstance:

int PyObject_IsInstance(PyObject *inst, PyObject *cls);
	Returns 1 if inst is an instance of the class cls or a subclass of cls, 
or 0 if not...

Second is PyObject_TypeCheck:

int PyObject_TypeCheck(PyObject *o, PyTypeObject *type);
	Return true if the object o is of type type or a subtype of type...

Now, I can see that IsInstance can take a tuple as the second argument 
and check the type of the first argument against every item in the 
tuple. I also see that TypeCheck was added in version 2.2. Why was it 
added? Its functionality already seems covered by IsInstance. Is it a 
new-style vs. old-style class thing?

-Kirk McDonald



More information about the Python-list mailing list