Title: remove dead code in PyErr_GivenExceptionMatches()
Type: performance Stage: resolved
Components: Interpreter Core Versions: Python 3.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: pitrou, scoder, serhiy.storchaka
Priority: normal Keywords:

Created on 2017-07-31 19:24 by scoder, last changed 2017-07-31 20:30 by serhiy.storchaka. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 2963 merged scoder, 2017-07-31 19:24
Messages (4)
msg299579 - (view) Author: Stefan Behnel (scoder) * (Python committer) Date: 2017-07-31 19:24
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) {
            res = 0;
        PyErr_Restore(exception, value, tb);

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.
See pull request.
msg299580 - (view) Author: Stefan Behnel (scoder) * (Python committer) Date: 2017-07-31 19:56
Looks like the switch from PyObject_IsSubclass() to PyType_IsSubtype() was made during the original Py3 development cycle. It should thus be safe to assume that the semantics are "as designed". :)

What about applying the patch also to 3.6 and older?
msg299584 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-07-31 20:27
New changeset e4c06bcca358c6dcb6393a75a1589ff6a2d45cde by Serhiy Storchaka (scoder) in branch 'master':
bpo-31091: Remove dead code in PyErr_GivenExceptionMatches(). (#2963)
msg299585 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-07-31 20:30
This is just a cleaning up. There is no bug in the old code. Usually such kind of changes are not backported.
Date User Action Args
2017-07-31 20:30:21serhiy.storchakasetstatus: open -> closed
resolution: fixed
messages: + msg299585

stage: patch review -> resolved
2017-07-31 20:27:49serhiy.storchakasetmessages: + msg299584
2017-07-31 19:56:29scodersetmessages: + msg299580
2017-07-31 19:40:21serhiy.storchakasetnosy: + pitrou, serhiy.storchaka

stage: patch review
2017-07-31 19:24:27scodercreate