This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Simplify exception handling in `doctest.py`
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.11
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: iritkatriel, sobolevn
Priority: normal Keywords: patch

Created on 2022-01-26 09:42 by sobolevn, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 30916 closed sobolevn, 2022-01-26 09:44
Messages (5)
msg411720 - (view) Author: Nikita Sobolev (sobolevn) * (Python triager) Date: 2022-01-26 09:42
Right now there are two places where `sys.exc_info()` calls are not required anymore:
1. https://github.com/python/cpython/blob/6e5a193816e1bdf11f5fb78d620995fd6987ccf8/Lib/doctest.py#L1352-L1353
2. https://github.com/python/cpython/blob/6e5a193816e1bdf11f5fb78d620995fd6987ccf8/Lib/doctest.py#L2640-L2641

There are also places where it is exposed as a part of public API (I am not going to change that, at least in this PR):
- https://github.com/python/cpython/blob/6e5a193816e1bdf11f5fb78d620995fd6987ccf8/Lib/doctest.py#L1757
- https://github.com/python/cpython/blob/6e5a193816e1bdf11f5fb78d620995fd6987ccf8/Lib/doctest.py#L1262

And some private APIs (out of scope as well):
- https://github.com/python/cpython/blob/6e5a193816e1bdf11f5fb78d620995fd6987ccf8/Lib/doctest.py#L244

PR is on its way!
msg411722 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2022-01-26 09:49
I don't think this is worth doing in a module where we can't completely get rid of the exc_info triplet.
msg411724 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2022-01-26 09:55
In other words, I don't see why it's an improvement to replace

    exception = sys.exc_info()

by 

    exception = type(exc), exc, exc.__traceback__

when sys.exc_info() does exactly what your inlined version does.
msg411728 - (view) Author: Nikita Sobolev (sobolevn) * (Python triager) Date: 2022-01-26 10:07
Fair enough! The only improvement is that we don't call `sys.exc_info` twice here: https://github.com/python/cpython/blob/6e5a193816e1bdf11f5fb78d620995fd6987ccf8/Lib/doctest.py#L2641-L2644

But, I think it is a minor thing.

Looks like I've misunderstood the long time goal of `sys.exc_info` refactorings. Thanks a lot for the feedback!
msg411730 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2022-01-26 10:16
In the long term we will want to not have the triplet, but this is a process that will take a few python versions to complete (when 3.11 is the oldest supported version). And it is not going to be simple.

In the meantime, where there is an advantage to removing exc_info because the code would be simplified or something else is changing nearby, we can do it. But I wouldn't remove exc_info just for the sake of it - such code churn makes it hard to backport other changes.
History
Date User Action Args
2022-04-11 14:59:55adminsetgithub: 90689
2022-01-26 10:16:22iritkatrielsetmessages: + msg411730
2022-01-26 10:07:07sobolevnsetstatus: open -> closed
resolution: not a bug
messages: + msg411728

stage: patch review -> resolved
2022-01-26 09:55:30iritkatrielsetmessages: + msg411724
2022-01-26 09:49:11iritkatrielsetmessages: + msg411722
2022-01-26 09:44:06sobolevnsetkeywords: + patch
stage: patch review
pull_requests: + pull_request29095
2022-01-26 09:42:50sobolevncreate