2012-02-26 20:29:14 -05:00
|
|
|
|
PEP: 415
|
|
|
|
|
Title: Implementing PEP 409 differently
|
|
|
|
|
Version: $Revision$
|
|
|
|
|
Last-Modified: $Date$
|
|
|
|
|
Author: Benjamin Peterson <benjamin@python.org>
|
2012-05-06 02:31:52 -04:00
|
|
|
|
BDFL-Delegate: Nick Coghlan
|
2012-05-14 08:08:40 -04:00
|
|
|
|
Status: Accepted
|
2012-02-26 20:29:14 -05:00
|
|
|
|
Type: Standards Track
|
|
|
|
|
Content-Type: text/x-rst
|
|
|
|
|
Created: 26-Feb-2012
|
2012-05-06 02:31:52 -04:00
|
|
|
|
Python-Version: 3.3
|
2012-02-26 20:29:14 -05:00
|
|
|
|
Post-History: 26-Feb-2012
|
2012-05-14 08:08:40 -04:00
|
|
|
|
Resolution: http://mail.python.org/pipermail/python-dev/2012-May/119467.html
|
2012-02-26 20:29:14 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Abstract
|
|
|
|
|
========
|
|
|
|
|
|
|
|
|
|
PEP 409 allows PEP 3134 exception contexts and causes to be suppressed when the
|
|
|
|
|
exception is printed. This is done using the ``raise exc from None``
|
|
|
|
|
syntax. This PEP proposes to implement context and cause suppression
|
|
|
|
|
differently.
|
|
|
|
|
|
2012-05-14 08:08:40 -04:00
|
|
|
|
|
|
|
|
|
PEP Acceptance
|
|
|
|
|
==============
|
|
|
|
|
|
|
|
|
|
This PEP was accepted by Nick Coghlan on the 14th of May, 2012.
|
|
|
|
|
|
|
|
|
|
|
2012-02-26 20:29:14 -05:00
|
|
|
|
Rationale
|
|
|
|
|
=========
|
|
|
|
|
|
|
|
|
|
PEP 409 changes ``__cause__`` to be ``Ellipsis`` by default. Then if
|
|
|
|
|
``__cause__`` is set to ``None`` by ``raise exc from None``, no context or cause
|
|
|
|
|
will be printed should the exception be uncaught.
|
|
|
|
|
|
|
|
|
|
The main problem with this scheme is it complicates the role of
|
|
|
|
|
``__cause__``. ``__cause__`` should indicate the cause of the exception not
|
|
|
|
|
whether ``__context__`` should be printed or not. This use of ``__cause__`` is
|
|
|
|
|
also not easily extended in the future. For example, we may someday want to
|
|
|
|
|
allow the programmer to select which of ``__context__`` and ``__cause__`` will
|
2012-02-26 20:39:52 -05:00
|
|
|
|
be printed. The PEP 409 implementation is not amenable to this.
|
2012-02-26 20:29:14 -05:00
|
|
|
|
|
|
|
|
|
The use of ``Ellipsis`` is a hack. Before PEP 409, ``Ellipsis`` was used
|
|
|
|
|
exclusively in extended slicing. Extended slicing has nothing to do with
|
|
|
|
|
exceptions, so it's not clear to someone inspecting an exception object why
|
|
|
|
|
``__cause__`` should be set to ``Ellipsis``. Using ``Ellipsis`` by default for
|
|
|
|
|
``__cause__`` makes it asymmetrical with ``__context__``.
|
|
|
|
|
|
2012-05-14 08:08:40 -04:00
|
|
|
|
|
2012-02-26 20:29:14 -05:00
|
|
|
|
Proposal
|
|
|
|
|
========
|
|
|
|
|
|
2012-02-27 18:59:27 -05:00
|
|
|
|
A new attribute on ``BaseException``, ``__suppress_context__``, will
|
2012-03-05 16:43:34 -05:00
|
|
|
|
be introduced. Whenever ``__cause__`` is set, ``__suppress_context__``
|
|
|
|
|
will be set to ``True``. In particular, ``raise exc from cause``
|
|
|
|
|
syntax will set ``exc.__suppress_context__`` to ``True``. Exception
|
|
|
|
|
printing code will check for that attribute to determine whether
|
|
|
|
|
context and cause will be printed. ``__cause__`` will return to its
|
|
|
|
|
original purpose and values.
|
2012-02-26 20:29:14 -05:00
|
|
|
|
|
|
|
|
|
There is precedence for ``__suppress_context__`` with the
|
|
|
|
|
``print_line_and_file`` exception attribute.
|
|
|
|
|
|
2012-02-27 10:51:11 -05:00
|
|
|
|
To summarize, ``raise exc from cause`` will be equivalent to::
|
|
|
|
|
|
|
|
|
|
exc.__cause__ = cause
|
|
|
|
|
raise exc
|
|
|
|
|
|
2012-03-05 16:43:34 -05:00
|
|
|
|
where ``exc.__cause__ = cause`` implicitly sets
|
|
|
|
|
``exc.__suppress_context__``.
|
|
|
|
|
|
2012-05-14 08:08:40 -04:00
|
|
|
|
|
2012-02-26 20:29:14 -05:00
|
|
|
|
Patches
|
|
|
|
|
=======
|
|
|
|
|
|
|
|
|
|
There is a patch on `Issue 14133`_.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
References
|
|
|
|
|
==========
|
|
|
|
|
|
|
|
|
|
.. _issue 14133:
|
2012-04-29 21:27:35 -04:00
|
|
|
|
http://bugs.python.org/issue14133
|
2012-02-26 20:29:14 -05:00
|
|
|
|
|
2012-05-14 08:08:40 -04:00
|
|
|
|
|
2012-02-26 20:29:14 -05:00
|
|
|
|
Copyright
|
|
|
|
|
=========
|
|
|
|
|
|
|
|
|
|
This document has been placed in the public domain.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
..
|
|
|
|
|
Local Variables:
|
|
|
|
|
mode: indented-text
|
|
|
|
|
indent-tabs-mode: nil
|
|
|
|
|
sentence-end-double-space: t
|
|
|
|
|
fill-column: 70
|
|
|
|
|
coding: utf-8
|
|
|
|
|
End:
|