summaryrefslogtreecommitdiffstats
path: root/Doc/library
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2023-02-20 21:54:19 (GMT)
committerGitHub <noreply@github.com>2023-02-20 21:54:19 (GMT)
commit4d3bc89a3f54c4f09756a9b644b3912bf54191a7 (patch)
tree2497cec92c8a3935c3a66efbb3a123ff204e6f8f /Doc/library
parent36854bbb240e417c0df6f0014924fcc899388186 (diff)
downloadcpython-4d3bc89a3f54c4f09756a9b644b3912bf54191a7.zip
cpython-4d3bc89a3f54c4f09756a9b644b3912bf54191a7.tar.gz
cpython-4d3bc89a3f54c4f09756a9b644b3912bf54191a7.tar.bz2
gh-102011: use sys.exception() instead of sys.exc_info() in docs where possible (#102012)
Diffstat (limited to 'Doc/library')
-rw-r--r--Doc/library/exceptions.rst2
-rw-r--r--Doc/library/traceback.rst21
-rw-r--r--Doc/library/types.rst2
-rw-r--r--Doc/library/wsgiref.rst2
4 files changed, 13 insertions, 14 deletions
diff --git a/Doc/library/exceptions.rst b/Doc/library/exceptions.rst
index 1217b81..4a57e9c 100644
--- a/Doc/library/exceptions.rst
+++ b/Doc/library/exceptions.rst
@@ -123,7 +123,7 @@ The following exceptions are used mostly as base classes for other exceptions.
try:
...
except SomeException:
- tb = sys.exc_info()[2]
+ tb = sys.exception().__traceback__
raise OtherException(...).with_traceback(tb)
.. method:: add_note(note)
diff --git a/Doc/library/traceback.rst b/Doc/library/traceback.rst
index 69818ba..561c852 100644
--- a/Doc/library/traceback.rst
+++ b/Doc/library/traceback.rst
@@ -16,9 +16,8 @@ interpreter.
.. index:: object: traceback
-The module uses traceback objects --- this is the object type that is stored in
-the :data:`sys.last_traceback` variable and returned as the third item from
-:func:`sys.exc_info`.
+The module uses traceback objects --- these are objects of type :class:`types.TracebackType`,
+which are assigned to the ``__traceback__`` field of :class:`BaseException` instances.
.. seealso::
@@ -81,7 +80,7 @@ The module defines the following functions:
.. function:: print_exc(limit=None, file=None, chain=True)
- This is a shorthand for ``print_exception(*sys.exc_info(), limit, file,
+ This is a shorthand for ``print_exception(sys.exception(), limit, file,
chain)``.
@@ -444,11 +443,11 @@ exception and traceback:
try:
lumberjack()
except IndexError:
- exc_type, exc_value, exc_traceback = sys.exc_info()
+ exc = sys.exception()
print("*** print_tb:")
- traceback.print_tb(exc_traceback, limit=1, file=sys.stdout)
+ traceback.print_tb(exc.__traceback__, limit=1, file=sys.stdout)
print("*** print_exception:")
- traceback.print_exception(exc_value, limit=2, file=sys.stdout)
+ traceback.print_exception(exc, limit=2, file=sys.stdout)
print("*** print_exc:")
traceback.print_exc(limit=2, file=sys.stdout)
print("*** format_exc, first and last line:")
@@ -456,12 +455,12 @@ exception and traceback:
print(formatted_lines[0])
print(formatted_lines[-1])
print("*** format_exception:")
- print(repr(traceback.format_exception(exc_value)))
+ print(repr(traceback.format_exception(exc)))
print("*** extract_tb:")
- print(repr(traceback.extract_tb(exc_traceback)))
+ print(repr(traceback.extract_tb(exc.__traceback__)))
print("*** format_tb:")
- print(repr(traceback.format_tb(exc_traceback)))
- print("*** tb_lineno:", exc_traceback.tb_lineno)
+ print(repr(traceback.format_tb(exc.__traceback__)))
+ print("*** tb_lineno:", exc.__traceback__.tb_lineno)
The output for the example would look similar to this:
diff --git a/Doc/library/types.rst b/Doc/library/types.rst
index cce0ad9..415413c 100644
--- a/Doc/library/types.rst
+++ b/Doc/library/types.rst
@@ -320,7 +320,7 @@ Standard names are defined for the following types:
.. class:: TracebackType(tb_next, tb_frame, tb_lasti, tb_lineno)
- The type of traceback objects such as found in ``sys.exc_info()[2]``.
+ The type of traceback objects such as found in ``sys.exception().__traceback__``.
See :ref:`the language reference <traceback-objects>` for details of the
available attributes and operations, and guidance on creating tracebacks
diff --git a/Doc/library/wsgiref.rst b/Doc/library/wsgiref.rst
index 75dea46..39a4c1b 100644
--- a/Doc/library/wsgiref.rst
+++ b/Doc/library/wsgiref.rst
@@ -674,7 +674,7 @@ input, output, and error streams.
This method is a WSGI application to generate an error page for the user. It is
only invoked if an error occurs before headers are sent to the client.
- This method can access the current error information using ``sys.exc_info()``,
+ This method can access the current error using ``sys.exception()``,
and should pass that information to *start_response* when calling it (as
described in the "Error Handling" section of :pep:`3333`).