-
-
Notifications
You must be signed in to change notification settings - Fork 32k
bpo-45711: Change exc_info related APIs to derive type and traceback from the exception instance #29780
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpo-45711: Change exc_info related APIs to derive type and traceback from the exception instance #29780
Changes from all commits
04407ce
e8645ff
971887a
995ec59
92835f0
4602710
7bc139f
05af230
f17222d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -655,6 +655,12 @@ and information about handling exceptions is in section :ref:`try`. | |
The ``__suppress_context__`` attribute to suppress automatic display of the | ||
exception context. | ||
|
||
.. versionchanged:: 3.11 | ||
If the traceback of the active exception is modified in an :keyword:`except` | ||
clause, a subsequent ``raise`` statement re-raises the exception with the | ||
modified traceback. Previously, the exception was re-raised with the | ||
traceback it had when it was caught. | ||
Comment on lines
+661
to
+662
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Isn't this a bug and that particular change should therefore be backported? I recently got surprised by this behavior of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I originally wanted to post this as an issue but discovered that the behavior seemingly disappeared when using Python 3.11. With some help I found out about this PR where one of the changes fixes the behavior of bare There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here's a short example to explain what I mean:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can't backport this change, it's way too invasive for that. This behaviour existed since 3.0, unfortunately. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you "raise e" instead of "raise" then you will see the edited traceback (but with the current frame added). |
||
|
||
.. _break: | ||
|
||
The :keyword:`!break` statement | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -181,6 +181,12 @@ Other CPython Implementation Changes | |
hash-based pyc files now use ``siphash13``, too. | ||
(Contributed by Inada Naoki in :issue:`29410`.) | ||
|
||
* When an active exception is re-raised by a :keyword:`raise` statement with no parameters, | ||
the traceback attached to this exception is now always ``sys.exc_info()[1].__traceback__``. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The use of |
||
This means that changes made to the traceback in the current :keyword:`except` clause are | ||
reflected in the re-raised exception. | ||
(Contributed by Irit Katriel in :issue:`45711`.) | ||
|
||
New Modules | ||
=========== | ||
|
||
|
@@ -266,6 +272,16 @@ sqlite3 | |
(Contributed by Erlend E. Aasland in :issue:`45828`.) | ||
|
||
|
||
sys | ||
--- | ||
|
||
* :func:`sys.exc_info` now derives the ``type`` and ``traceback`` fields | ||
from the ``value`` (the exception instance), so when an exception is | ||
modified while it is being handled, the changes are reflected in | ||
the results of subsequent calls to :func:`exc_info`. | ||
(Contributed by Irit Katriel in :issue:`45711`.) | ||
|
||
|
||
threading | ||
--------- | ||
|
||
|
@@ -579,6 +595,17 @@ New Features | |
suspend and resume tracing and profiling. | ||
(Contributed by Victor Stinner in :issue:`43760`.) | ||
|
||
* :c:func:`PyErr_SetExcInfo()` no longer uses the ``type`` and ``traceback`` | ||
arguments, the interpreter now derives those values from the exception | ||
instance (the ``value`` argument). The function still steals references | ||
of all three arguments. | ||
(Contributed by Irit Katriel in :issue:`45711`.) | ||
|
||
* :c:func:`PyErr_GetExcInfo()` now derives the ``type`` and ``traceback`` | ||
fields of the result from the exception instance (the ``value`` field). | ||
(Contributed by Irit Katriel in :issue:`45711`.) | ||
|
||
|
||
Porting to Python 3.11 | ||
---------------------- | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
The three values of ``exc_info`` are now always consistent with each other. | ||
In particular, the ``type`` and ``traceback`` fields are now derived from | ||
the exception instance. This impacts the return values of :func:`sys.exc_info` | ||
and :c:func:`PyErr_GetExcInfo()` if the exception instance is modified while | ||
the exception is handled, as well as :c:func:`PyErr_SetExcInfo()`, which now | ||
ignores the ``type`` and ``traceback`` arguments provided to it. |
Uh oh!
There was an error while loading. Please reload this page.