]> granicus.if.org Git - python/commitdiff
bpo-31091: Remove dead code in PyErr_GivenExceptionMatches(). (#2963)
authorscoder <stefan_ml@behnel.de>
Mon, 31 Jul 2017 20:27:46 +0000 (22:27 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Mon, 31 Jul 2017 20:27:46 +0000 (23:27 +0300)
According to the comment, there was previously a call to PyObject_IsSubclass() involved which could fail, but since it was replaced with a call to PyType_IsSubtype(), it can no longer fail.

Python/errors.c

index 3785e6981c6498db88aa6402fca2cb3315f399c3..261dd7b27cbd1019936f90fddc2ba96ca3160e6a 100644 (file)
@@ -191,19 +191,7 @@ PyErr_GivenExceptionMatches(PyObject *err, PyObject *exc)
         err = PyExceptionInstance_Class(err);
 
     if (PyExceptionClass_Check(err) && PyExceptionClass_Check(exc)) {
-        int res = 0;
-        PyObject *exception, *value, *tb;
-        PyErr_Fetch(&exception, &value, &tb);
-        /* 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);
-            res = 0;
-        }
-        PyErr_Restore(exception, value, tb);
-        return res;
+        return PyType_IsSubtype((PyTypeObject *)err, (PyTypeObject *)exc);
     }
 
     return err == exc;