comparison 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
comparison
equal deleted inserted replaced
48874:4db1f5098175 48875:d6e86a96f9b3
158 158
159 if (PyExceptionClass_Check(err) && PyExceptionClass_Check(exc)) { 159 if (PyExceptionClass_Check(err) && PyExceptionClass_Check(exc)) {
160 int res = 0; 160 int res = 0;
161 PyObject *exception, *value, *tb; 161 PyObject *exception, *value, *tb;
162 PyErr_Fetch(&exception, &value, &tb); 162 PyErr_Fetch(&exception, &value, &tb);
163 res = PyObject_IsSubclass(err, exc); 163 /* PyObject_IsSubclass() can recurse and therefore is
164 not safe (see test_bad_getattr in test.pickletester). */
165 res = PyType_IsSubtype((PyTypeObject *)err, (PyTypeObject *)exc);
164 /* This function must not fail, so print the error here */ 166 /* This function must not fail, so print the error here */
165 if (res == -1) { 167 if (res == -1) {
166 PyErr_WriteUnraisable(err); 168 PyErr_WriteUnraisable(err);
167 /* issubclass did not succeed */
168 res = 0; 169 res = 0;
169 } 170 }
170 PyErr_Restore(exception, value, tb); 171 PyErr_Restore(exception, value, tb);
171 return res; 172 return res;
172 } 173 }