Mercurial > cpython-lru_cache-weakref
diff Python/errors.c @ 48875:d6e86a96f9b3
Issue #2534: speed up isinstance() and issubclass() by 50-70%, so as to
match Python 2.5 speed despite the __instancecheck__ / __subclasscheck__
mechanism. In the process, fix a bug where isinstance() and issubclass(),
when given a tuple of classes as second argument, were looking up
__instancecheck__ / __subclasscheck__ on the tuple rather than on each
type object.
Reviewed by Benjamin Peterson and Raymond Hettinger.
| author | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| date | Tue, 26 Aug 2008 22:40:48 +0000 |
| parents | 85b67fb5672b |
| children | c562c8dae49a |
line wrap: on
line diff
--- a/Python/errors.c Tue Aug 26 22:02:58 2008 +0000 +++ b/Python/errors.c Tue Aug 26 22:40:48 2008 +0000 @@ -160,11 +160,12 @@ int res = 0; PyObject *exception, *value, *tb; PyErr_Fetch(&exception, &value, &tb); - res = PyObject_IsSubclass(err, exc); + /* PyObject_IsSubclass() can recurse and therefore is + not safe (see test_bad_getattr in test.pickletester). */ + res = PyType_IsSubtype((PyTypeObject *)err, (PyTypeObject *)exc); /* This function must not fail, so print the error here */ if (res == -1) { PyErr_WriteUnraisable(err); - /* issubclass did not succeed */ res = 0; } PyErr_Restore(exception, value, tb);
