diff options
author | Irit Katriel <1055913+iritkatriel@users.noreply.github.com> | 2021-11-30 22:37:04 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-30 22:37:04 (GMT) |
commit | 8a45ca542a65ea27e7acaa44a4c833a27830e796 (patch) | |
tree | 8cc5563159c3c11b88d0f9c9b9164ed21a9d9e7f /Doc | |
parent | af8c8caaf5e07c02202d736a31f6a2f7e27819b8 (diff) | |
download | cpython-8a45ca542a65ea27e7acaa44a4c833a27830e796.zip cpython-8a45ca542a65ea27e7acaa44a4c833a27830e796.tar.gz cpython-8a45ca542a65ea27e7acaa44a4c833a27830e796.tar.bz2 |
bpo-45711: Change exc_info related APIs to derive type and traceback from the exception instance (GH-29780)
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/c-api/exceptions.rst | 7 | ||||
-rw-r--r-- | Doc/library/sys.rst | 11 | ||||
-rw-r--r-- | Doc/reference/simple_stmts.rst | 6 | ||||
-rw-r--r-- | Doc/whatsnew/3.11.rst | 27 |
4 files changed, 47 insertions, 4 deletions
diff --git a/Doc/c-api/exceptions.rst b/Doc/c-api/exceptions.rst index 5d90248..27feab9 100644 --- a/Doc/c-api/exceptions.rst +++ b/Doc/c-api/exceptions.rst @@ -482,7 +482,6 @@ Querying the error indicator to an exception that was *already caught*, not to an exception that was freshly raised. This function steals the references of the arguments. To clear the exception state, pass ``NULL`` for all three arguments. - For general rules about the three arguments, see :c:func:`PyErr_Restore`. .. note:: @@ -493,6 +492,12 @@ Querying the error indicator .. versionadded:: 3.3 + .. versionchanged:: 3.11 + The ``type`` and ``traceback`` arguments are no longer used and + can be NULL. The interpreter now derives them from the exception + instance (the ``value`` argument). The function still steals + references of all three arguments. + Signal Handling =============== diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst index 175fc09..7d1b21f 100644 --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -396,9 +396,14 @@ always available. ``(type, value, traceback)``. Their meaning is: *type* gets the type of the exception being handled (a subclass of :exc:`BaseException`); *value* gets the exception instance (an instance of the exception type); *traceback* gets - a :ref:`traceback object <traceback-objects>` which encapsulates the call - stack at the point where the exception originally occurred. - + a :ref:`traceback object <traceback-objects>` which typically encapsulates + the call stack at the point where the exception last occurred. + + .. versionchanged:: 3.11 + The ``type`` and ``traceback`` fields are now derived 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`. .. data:: exec_prefix diff --git a/Doc/reference/simple_stmts.rst b/Doc/reference/simple_stmts.rst index bb1209d..3d02074 100644 --- a/Doc/reference/simple_stmts.rst +++ b/Doc/reference/simple_stmts.rst @@ -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. + .. _break: The :keyword:`!break` statement diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 8db26cd..6853c04 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -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__``. + 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 ---------------------- |