[New-bugs-announce] [issue47099] Replace with_traceback() with exception chaining and reraising

Oleg Iarygin report at bugs.python.org
Wed Mar 23 06:42:51 EDT 2022

New submission from Oleg Iarygin <oleg at arhadthedev.net>:

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

components: Library (Lib)
messages: 415864
nosy: arhadthedev
priority: normal
severity: normal
status: open
title: Replace with_traceback() with exception chaining and reraising
type: enhancement
versions: Python 3.11

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list