Index: Include/abstract.h
===================================================================
--- Include/abstract.h (revision 62102)
+++ Include/abstract.h (working copy)
@@ -1390,6 +1390,11 @@
/* issubclass(object, typeorclass) */
+PyAPI_FUNC(int) _PyObject_RealIsInstance(PyObject *inst, PyObject *cls);
+
+PyAPI_FUNC(int) _PyObject_RealIsSubclass(PyObject *derived, PyObject *cls);
+
+
#ifdef __cplusplus
}
#endif
Index: Objects/abstract.c
===================================================================
--- Objects/abstract.c (revision 62102)
+++ Objects/abstract.c (working copy)
@@ -2940,6 +2940,12 @@
return recursive_isinstance(inst, cls, Py_GetRecursionLimit());
}
+int
+_PyObject_RealIsInstance(PyObject *inst, PyObject *cls)
+{
+ return recursive_isinstance(inst, cls, Py_GetRecursionLimit());
+}
+
static int
recursive_issubclass(PyObject *derived, PyObject *cls, int recursion_depth)
{
@@ -2990,6 +2996,12 @@
}
int
+_PyObject_RealIsSubclass(PyObject *derived, PyObject *cls)
+{
+ return recursive_issubclass(derived, cls, Py_GetRecursionLimit());
+}
+
+int
PyObject_IsSubclass(PyObject *derived, PyObject *cls)
{
static PyObject *name = NULL;
Index: Objects/typeobject.c
===================================================================
--- Objects/typeobject.c (revision 62102)
+++ Objects/typeobject.c (working copy)
@@ -572,6 +572,49 @@
return result;
}
+static PyObject *
+type___instancecheck__(PyObject *type, void *inst)
+{
+ switch (_PyObject_RealIsInstance(inst, type)) {
+ case -1:
+ return NULL;
+ case 0:
+ Py_RETURN_FALSE;
+ default:
+ Py_RETURN_TRUE;
+ }
+}
+
+
+static PyObject *
+type_get_instancecheck(PyObject *type, void *context)
+{
+ static PyMethodDef ml = {"__instancecheck__",
+ type___instancecheck__, METH_O };
+ return PyCFunction_New(&ml, type);
+}
+
+static PyObject *
+type___subclasscheck__(PyObject *type, PyObject *inst)
+{
+ switch (_PyObject_RealIsSubclass(inst, type)) {
+ case -1:
+ return NULL;
+ case 0:
+ Py_RETURN_FALSE;
+ default:
+ Py_RETURN_TRUE;
+ }
+}
+
+static PyObject *
+type_get_subclasscheck(PyObject *type, void *context)
+{
+ static PyMethodDef ml = {"__subclasscheck__",
+ type___subclasscheck__, METH_O };
+ return PyCFunction_New(&ml, type);
+}
+
static PyGetSetDef type_getsets[] = {
{"__name__", (getter)type_name, (setter)type_set_name, NULL},
{"__bases__", (getter)type_get_bases, (setter)type_set_bases, NULL},
@@ -580,6 +623,8 @@
(setter)type_set_abstractmethods, NULL},
{"__dict__", (getter)type_dict, NULL, NULL},
{"__doc__", (getter)type_get_doc, NULL, NULL},
+ {"__instancecheck__", (getter)type_get_instancecheck, NULL, NULL},
+ {"__subclasscheck__", (getter)type_get_subclasscheck, NULL, NULL},
{0}
};