Skip to content

Commit 9a70989

Browse files
[3.11] Docs: emphasise warning and add accurate markups for sys.unraisablehook (pythonGH-108105) (python#108110)
(cherry picked from commit cc58ec9) Co-authored-by: Erlend E. Aasland <[email protected]>
1 parent 6dd1729 commit 9a70989

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

Doc/library/sys.rst

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,35 +1747,39 @@ always available.
17471747

17481748
The *unraisable* argument has the following attributes:
17491749

1750-
* *exc_type*: Exception type.
1751-
* *exc_value*: Exception value, can be ``None``.
1752-
* *exc_traceback*: Exception traceback, can be ``None``.
1753-
* *err_msg*: Error message, can be ``None``.
1754-
* *object*: Object causing the exception, can be ``None``.
1750+
* :attr:`!exc_type`: Exception type.
1751+
* :attr:`!exc_value`: Exception value, can be ``None``.
1752+
* :attr:`!exc_traceback`: Exception traceback, can be ``None``.
1753+
* :attr:`!err_msg`: Error message, can be ``None``.
1754+
* :attr:`!object`: Object causing the exception, can be ``None``.
17551755

1756-
The default hook formats *err_msg* and *object* as:
1756+
The default hook formats :attr:`!err_msg` and :attr:`!object` as:
17571757
``f'{err_msg}: {object!r}'``; use "Exception ignored in" error message
1758-
if *err_msg* is ``None``.
1758+
if :attr:`!err_msg` is ``None``.
17591759

17601760
:func:`sys.unraisablehook` can be overridden to control how unraisable
17611761
exceptions are handled.
17621762

1763-
Storing *exc_value* using a custom hook can create a reference cycle. It
1764-
should be cleared explicitly to break the reference cycle when the
1765-
exception is no longer needed.
1763+
.. seealso::
1764+
1765+
:func:`excepthook` which handles uncaught exceptions.
1766+
1767+
.. warning::
17661768

1767-
Storing *object* using a custom hook can resurrect it if it is set to an
1768-
object which is being finalized. Avoid storing *object* after the custom
1769-
hook completes to avoid resurrecting objects.
1769+
Storing :attr:`!exc_value` using a custom hook can create a reference cycle.
1770+
It should be cleared explicitly to break the reference cycle when the
1771+
exception is no longer needed.
17701772

1771-
See also :func:`excepthook` which handles uncaught exceptions.
1773+
Storing :attr:`!object` using a custom hook can resurrect it if it is set to an
1774+
object which is being finalized. Avoid storing :attr:`!object` after the custom
1775+
hook completes to avoid resurrecting objects.
17721776

17731777
.. audit-event:: sys.unraisablehook hook,unraisable sys.unraisablehook
17741778

17751779
Raise an auditing event ``sys.unraisablehook`` with arguments
1776-
``hook``, ``unraisable`` when an exception that cannot be handled occurs.
1777-
The ``unraisable`` object is the same as what will be passed to the hook.
1778-
If no hook has been set, ``hook`` may be ``None``.
1780+
*hook*, *unraisable* when an exception that cannot be handled occurs.
1781+
The *unraisable* object is the same as what will be passed to the hook.
1782+
If no hook has been set, *hook* may be ``None``.
17791783

17801784
.. versionadded:: 3.8
17811785

0 commit comments

Comments
 (0)