Worked with Alex Martelli at the Goolge Python Sprint.
Index: Objects/abstract.c =================================================================== --- Objects/abstract.c (revision 57470) +++ Objects/abstract.c (working copy) @@ -2275,6 +2275,27 @@ int PyObject_IsInstance(PyObject *inst, PyObject *cls) { + PyObject *t, *v, *tb; + PyObject *checker; + PyErr_Fetch(&t, &v, &tb); + checker = PyObject_GetAttrString(cls, "__instancecheck__"); + PyErr_Restore(t, v, tb); + if (checker != NULL) { + PyObject *res; + int ok = -1; + if (Py_EnterRecursiveCall(" in __instancecheck__")) { + Py_DECREF(checker); + return ok; + } + res = PyObject_CallFunctionObjArgs(checker, inst, NULL); + Py_LeaveRecursiveCall(); + Py_DECREF(checker); + if (res != NULL) { + ok = PyObject_IsTrue(res); + Py_DECREF(res); + } + return ok; + } return recursive_isinstance(inst, cls, Py_GetRecursionLimit()); } @@ -2330,6 +2351,25 @@ int PyObject_IsSubclass(PyObject *derived, PyObject *cls) { + PyObject *t, *v, *tb; + PyObject *checker; + PyErr_Fetch(&t, &v, &tb); + checker = PyObject_GetAttrString(cls, "__subclasscheck__"); + PyErr_Restore(t, v, tb); + if (checker != NULL) { + PyObject *res; + int ok = -1; + if (Py_EnterRecursiveCall(" in __subclasscheck__")) + return ok; + res = PyObject_CallFunctionObjArgs(checker, derived, NULL); + Py_LeaveRecursiveCall(); + Py_DECREF(checker); + if (res != NULL) { + ok = PyObject_IsTrue(res); + Py_DECREF(res); + } + return ok; + } return recursive_issubclass(derived, cls, Py_GetRecursionLimit()); }
_______________________________________________ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com