diff -r b15c5a66213f Objects/abstract.c --- a/Objects/abstract.c Thu Oct 02 12:39:02 2014 +0200 +++ b/Objects/abstract.c Thu Oct 02 13:37:21 2014 +0200 @@ -2557,6 +2557,11 @@ PyObject_IsInstance(PyObject *inst, PyOb return r; } + if (Py_TYPE(cls) == &PyType_Type) { + /* We know what type's __instancecheck__ does. */ + return recursive_isinstance(inst, cls); + } + checker = _PyObject_LookupSpecial(cls, &PyId___instancecheck__); if (checker != NULL) { PyObject *res; @@ -2576,6 +2581,7 @@ PyObject_IsInstance(PyObject *inst, PyOb } else if (PyErr_Occurred()) return -1; + /* Probably never reached anymore. */ return recursive_isinstance(inst, cls); } @@ -2603,6 +2609,10 @@ PyObject_IsSubclass(PyObject *derived, P _Py_IDENTIFIER(__subclasscheck__); PyObject *checker; + /* Quick test for an exact match */ + if (derived == cls) + return 1; + if (PyTuple_Check(cls)) { Py_ssize_t i; Py_ssize_t n; @@ -2622,6 +2632,11 @@ PyObject_IsSubclass(PyObject *derived, P return r; } + if (Py_TYPE(cls) == &PyType_Type) { + /* We know what type's __subclasscheck__ does. */ + return recursive_issubclass(derived, cls); + } + checker = _PyObject_LookupSpecial(cls, &PyId___subclasscheck__); if (checker != NULL) { PyObject *res; @@ -2641,6 +2656,7 @@ PyObject_IsSubclass(PyObject *derived, P } else if (PyErr_Occurred()) return -1; + /* Probably never reached anymore. */ return recursive_issubclass(derived, cls); }