Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f5dd914

Browse files
committed
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.
1 parent 6cedf82 commit f5dd914

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

Python/bltinmodule.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,18 +1627,23 @@ builtin_isinstance(self, args)
16271627

16281628
if (!PyArg_ParseTuple(args, "OO", &inst, &cls))
16291629
return NULL;
1630-
if (!PyClass_Check(cls)) {
1631-
PyErr_SetString(PyExc_TypeError,
1632-
"second argument must be a class");
1633-
return NULL;
1630+
if (PyType_Check(cls)) {
1631+
retval = (inst->ob_type == cls);
16341632
}
1635-
1636-
if (!PyInstance_Check(inst))
1637-
retval = 0;
16381633
else {
1639-
PyObject *inclass =
1640-
(PyObject*)((PyInstanceObject*)inst)->in_class;
1641-
retval = PyClass_IsSubclass(inclass, cls);
1634+
if (!PyClass_Check(cls)) {
1635+
PyErr_SetString(PyExc_TypeError,
1636+
"second argument must be a class");
1637+
return NULL;
1638+
}
1639+
1640+
if (!PyInstance_Check(inst))
1641+
retval = 0;
1642+
else {
1643+
PyObject *inclass =
1644+
(PyObject*)((PyInstanceObject*)inst)->in_class;
1645+
retval = PyClass_IsSubclass(inclass, cls);
1646+
}
16421647
}
16431648
return PyInt_FromLong(retval);
16441649
}

0 commit comments

Comments
 (0)