Skip to content

Commit cc58ec9

Browse files
Docs: emphasise warning and add accurate markups for sys.unraisablehook (python#108105)
1 parent 02079b0 commit cc58ec9

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
@@ -1811,35 +1811,39 @@ always available.
18111811

18121812
The *unraisable* argument has the following attributes:
18131813

1814-
* *exc_type*: Exception type.
1815-
* *exc_value*: Exception value, can be ``None``.
1816-
* *exc_traceback*: Exception traceback, can be ``None``.
1817-
* *err_msg*: Error message, can be ``None``.
1818-
* *object*: Object causing the exception, can be ``None``.
1814+
* :attr:`!exc_type`: Exception type.
1815+
* :attr:`!exc_value`: Exception value, can be ``None``.
1816+
* :attr:`!exc_traceback`: Exception traceback, can be ``None``.
1817+
* :attr:`!err_msg`: Error message, can be ``None``.
1818+
* :attr:`!object`: Object causing the exception, can be ``None``.
18191819

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

18241824
:func:`sys.unraisablehook` can be overridden to control how unraisable
18251825
exceptions are handled.
18261826

1827-
Storing *exc_value* using a custom hook can create a reference cycle. It
1828-
should be cleared explicitly to break the reference cycle when the
1829-
exception is no longer needed.
1827+
.. seealso::
1828+
1829+
:func:`excepthook` which handles uncaught exceptions.
1830+
1831+
.. warning::
18301832

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

1835-
See also :func:`excepthook` which handles uncaught exceptions.
1837+
Storing :attr:`!object` using a custom hook can resurrect it if it is set to an
1838+
object which is being finalized. Avoid storing :attr:`!object` after the custom
1839+
hook completes to avoid resurrecting objects.
18361840

18371841
.. audit-event:: sys.unraisablehook hook,unraisable sys.unraisablehook
18381842

18391843
Raise an auditing event ``sys.unraisablehook`` with arguments
1840-
``hook``, ``unraisable`` when an exception that cannot be handled occurs.
1841-
The ``unraisable`` object is the same as what will be passed to the hook.
1842-
If no hook has been set, ``hook`` may be ``None``.
1844+
*hook*, *unraisable* when an exception that cannot be handled occurs.
1845+
The *unraisable* object is the same as what will be passed to the hook.
1846+
If no hook has been set, *hook* may be ``None``.
18431847

18441848
.. versionadded:: 3.8
18451849

0 commit comments

Comments
 (0)