summaryrefslogtreecommitdiffstats
path: root/Python/bltinmodule.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-12-02 19:11:45 (GMT)
committerGuido van Rossum <guido@python.org>1997-12-02 19:11:45 (GMT)
commitf5dd914196dc4c55394832b3de62fb621b4482e2 (patch)
treebca122334eb4767225ba1220e86078a25dee8dca /Python/bltinmodule.c
parent6cedf82ac1080eaf72b6d2703b609071a120b3eb (diff)
downloadcpython-f5dd914196dc4c55394832b3de62fb621b4482e2.zip
cpython-f5dd914196dc4c55394832b3de62fb621b4482e2.tar.gz
cpython-f5dd914196dc4c55394832b3de62fb621b4482e2.tar.bz2
Support type objects in isinstance().
E.g. isinstance('',types.StringType) will return true now instead of raising a TypeError exception. This is for JPython compatibility.
Diffstat (limited to 'Python/bltinmodule.c')
-rw-r--r--Python/bltinmodule.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index f2839ac..4019559 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -1627,18 +1627,23 @@ builtin_isinstance(self, args)
if (!PyArg_ParseTuple(args, "OO", &inst, &cls))
return NULL;
- if (!PyClass_Check(cls)) {
- PyErr_SetString(PyExc_TypeError,
- "second argument must be a class");
- return NULL;
+ if (PyType_Check(cls)) {
+ retval = (inst->ob_type == cls);
}
-
- if (!PyInstance_Check(inst))
- retval = 0;
else {
- PyObject *inclass =
- (PyObject*)((PyInstanceObject*)inst)->in_class;
- retval = PyClass_IsSubclass(inclass, cls);
+ if (!PyClass_Check(cls)) {
+ PyErr_SetString(PyExc_TypeError,
+ "second argument must be a class");
+ return NULL;
+ }
+
+ if (!PyInstance_Check(inst))
+ retval = 0;
+ else {
+ PyObject *inclass =
+ (PyObject*)((PyInstanceObject*)inst)->in_class;
+ retval = PyClass_IsSubclass(inclass, cls);
+ }
}
return PyInt_FromLong(retval);
}