PEP 415: Implement suppression of __context__ display with an exception attribute

This replaces the original PEP 409 implementation. See #14133.
This commit is contained in:
Benjamin Peterson 2012-05-14 22:09:31 -07:00
parent d91dc62379
commit d5a1c44455
12 changed files with 80 additions and 79 deletions

View file

@ -39,18 +39,17 @@ When raising (or re-raising) an exception in an :keyword:`except` clause
new exception is not handled the traceback that is eventually displayed will
include the originating exception(s) and the final exception.
This implicit exception chain can be made explicit by using :keyword:`from`
with :keyword:`raise`. The single argument to :keyword:`from` must be an
exception or :const:`None`, and it will be set as :attr:`__cause__` on the
raised exception. If :attr:`__cause__` is an exception it will be displayed
instead of :attr:`__context__`; if :attr:`__cause__` is None,
:attr:`__context__` will not be displayed by the default exception handling
code. (Note: the default value for :attr:`__context__` is :const:`None`,
while the default value for :attr:`__cause__` is :const:`Ellipsis`.)
This implicit exception chain can be made explicit by using :keyword:`from` with
:keyword:`raise`. The single argument to :keyword:`from` must be an exception
or ``None``. It will be set as :attr:`__cause__` on the raised exception.
Setting :attr:`__cause__` implicitly sets the :attr:`__suppress_context__` to
``True``. If :attr:`__cause__` is an exception, it will be displayed. If
:attr:`__cause__` is present or :attr:`__suppress_context__` has a true value,
:attr:`__context__` will not be displayed.
In either case, the default exception handling code will not display
any of the remaining links in the :attr:`__context__` chain if
:attr:`__cause__` has been set.
In either case, the default exception handling code will not display any of the
remaining links in the :attr:`__context__` chain if :attr:`__cause__` has been
set.
Base classes