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: Replace with_traceback() with exception chaining and reraising
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.11
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: arhadthedev, iritkatriel
Priority: normal Keywords: patch

Created on 2022-03-23 10:42 by arhadthedev, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 32074 merged arhadthedev, 2022-03-23 11:17
Messages (2)
msg415864 - (view) Author: Oleg Iarygin (arhadthedev) * Date: 2022-03-23 10:42
Currently, exception chaining in Lib/ modules is implemented with pre-3.11 `raise Foo(...).with_traceback(sys.exc_info()[2])`. However, this approach can be simplified:

1. PEP 3134 introduced a proper `raise Foo(...) from bar` construction that takes a parent exception instead of its stack traceback

2. Without the traceback required, we partially get rid of `sys.exc_info` thus reducing active tapping into global internals

A report printed into a console remains the same except a line:

> During handling of the above exception, another exception occurred

replaced with:

> The above exception was the direct cause of the following exception
msg415872 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2022-03-23 13:35
You don't need sys.exc_info() for the traceback anymore.

except Exception as e:
    raise OSError('blah').with_traceback(e.__traceback__)
History
Date User Action Args
2022-04-11 14:59:57adminsetgithub: 91255
2022-03-30 15:11:25arhadthedevsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2022-03-23 13:35:34iritkatrielsetnosy: + iritkatriel
messages: + msg415872
2022-03-23 11:17:49arhadthedevsetkeywords: + patch
stage: patch review
pull_requests: + pull_request30162
2022-03-23 10:42:51arhadthedevcreate