8000 gh-101100: Improve docs on exception attributes by AlexWaygood · Pull Request #113057 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-101100: Improve docs on exception attributes #113057

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

Merged
merged 6 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Various improvements
  • Loading branch information
AlexWaygood committed Dec 13, 2023
commit 7bd05a57de51c0d45f82d885a05f8980ca8662cc
16 changes: 8 additions & 8 deletions Doc/c-api/exceptions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -754,8 +754,8 @@ Exception Objects
.. c:function:: PyObject* PyException_GetTraceback(PyObject *ex)

Return the traceback associated with the exception as a new reference, as
accessible from Python through :attr:`~BaseException.__traceback__`.
If there is no
accessible from Python through the :attr:`~BaseException.__traceback__`
attribute. If there is no
traceback associated, this returns ``NULL``.


Expand All @@ -769,8 +769,8 @@ Exception Objects

Return the context (another exception instance during whose handling *ex* was
raised) associated with the exception as a new reference, as accessible from
Python through :attr:`~BaseException.__context__`. If there is no context
associated, this returns ``NULL``.
Python through the :attr:`~BaseException.__context__` attribute.
If there is no context associated, this returns ``NULL``.


.. c:function:: void PyException_SetContext(PyObject *ex, PyObject *ctx)
Expand All @@ -784,8 +784,8 @@ Exception Objects

Return the cause (either an exception instance, or ``None``,
set by ``raise ... from ...``) associated with the exception as a new
reference, as accessible from Python through
:attr:`~BaseException.__cause__`.
reference, as accessible from Python through the
:attr:`~BaseException.__cause__` attribute.


.. c:function:: void PyException_SetCause(PyObject *ex, PyObject *cause)
Expand All @@ -794,8 +794,8 @@ Exception Objects
it. There is no type check to make sure that *cause* is either an exception
instance or ``None``. This steals a reference to *cause*.

:attr:`~BaseException.__suppress_context__` is implicitly set to ``True`` by
this function.
The :attr:`~BaseException.__suppress_context__` attribute is implicitly set
to ``True`` by this function.


.. c:function:: PyObject* PyException_GetArgs(PyObject *ex)
Expand Down
7 changes: 5 additions & 2 deletions Doc/library/exceptions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,16 @@ Exception context
__context__ (exception attribute)
__suppress_context__ (exception attribute)

Three attributes on exception objects provide information about the context in
which an the exception was raised:

.. attribute:: BaseException.__context__
BaseException.__cause__
BaseException.__suppress_context__

When raising a new exception while another exception
is already being handled, the new exception's
:attr:`__context__` attribute is automatically set to the handled
:attr:`!__context__` attribute is automatically set to the handled
exception. An exception may be handled when an :keyword:`except` or
:keyword:`finally` clause, or a :keyword:`with` statement, is used.

Expand Down Expand Up @@ -139,7 +142,7 @@ The following exceptions are used mostly as base classes for other exceptions.

A writable field that holds the
:ref:`traceback object <traceback-objects>` associated with this
exception. See also :ref:`raise`.
exception. See also: :ref:`raise`.

.. method:: add_note(note)

Expand Down
4 changes: 2 additions & 2 deletions Doc/library/traceback.rst
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ capture data for later printing in a lightweight fashion.
*capture_locals* are as for the :class:`StackSummary` class.

If *compact* is true, only data that is required by
:class:`!TracebackException`'s
``format`` method is saved in the class attributes. In particular, the
:class:`!TracebackException`'s :meth:`format` method
is saved in the class attributes. In particular, the
:attr:`__context__` field is calculated only if :attr:`__cause__` is
``None`` and :attr:`__suppress_context__` is false.

Expand Down
0