Movatterモバイル変換


[0]ホーム

URL:


[Python-Dev] PEP 415: Implementing PEP 409 differently

Benjamin Petersonbenjamin at python.org
Mon Feb 27 02:30:10 CET 2012


PEP: 415Title: Implementing PEP 409 differentlyVersion: $Revision$Last-Modified: $Date$Author: Benjamin Peterson <benjamin at python.org>Status: DraftType: Standards TrackContent-Type: text/x-rstCreated: 26-Feb-2012Post-History: 26-Feb-2012Abstract========PEP 409 allows PEP 3134 exception contexts and causes to be suppressed when theexception is printed. This is done using the ``raise exc from None``syntax. This PEP proposes to implement context and cause suppressiondifferently.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 causewill 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 notwhether ``__context__`` should be printed or not. This use of ``__cause__`` isalso not easily extended in the future. For example, we may someday want toallow the programmer to select which of ``__context__`` and ``__cause__`` willbe printed. The PEP 409 implementation is not amendable to this.The use of ``Ellipsis`` is a hack. Before PEP 409, ``Ellipsis`` was usedexclusively in extended slicing. Extended slicing has nothing to do withexceptions, 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__``.Proposal========A new attribute on ``BaseException``, ``__suppress_context__``, will beintroduced. The ``raise exc from None`` syntax will cause``exc.__suppress_context__`` to be set to ``True``. Exception printing code willcheck for the attribute to determine whether context and cause will beprinted. ``__cause__`` will return to its original purpose and values.There is precedence for ``__suppress_context__`` with the``print_line_and_file`` exception attribute.Patches=======There is a patch on `Issue 14133`_.References==========.. _issue 14133:http://bugs.python.org/issue6210Copyright=========This document has been placed in the public domain.


More information about the Python-Devmailing list

[8]ページ先頭

©2009-2025 Movatter.jp