summaryrefslogtreecommitdiffstats
path: root/Doc/whatsnew/3.3.rst
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2012-02-26 07:49:52 (GMT)
committerNick Coghlan <ncoghlan@gmail.com>2012-02-26 07:49:52 (GMT)
commitab7bf2143e67ddc1510413fa0d7f9c621adf22fa (patch)
tree62a24ed4f57e4db638ebde745bb83e2e09fc86e3 /Doc/whatsnew/3.3.rst
parentcda6b6d60d96e6f755da92deb5e4066839095791 (diff)
downloadcpython-ab7bf2143e67ddc1510413fa0d7f9c621adf22fa.zip
cpython-ab7bf2143e67ddc1510413fa0d7f9c621adf22fa.tar.gz
cpython-ab7bf2143e67ddc1510413fa0d7f9c621adf22fa.tar.bz2
Close issue #6210: Implement PEP 409
Diffstat (limited to 'Doc/whatsnew/3.3.rst')
-rw-r--r--Doc/whatsnew/3.3.rst64
1 files changed, 64 insertions, 0 deletions
diff --git a/Doc/whatsnew/3.3.rst b/Doc/whatsnew/3.3.rst
index 560331f..9023dfa 100644
--- a/Doc/whatsnew/3.3.rst
+++ b/Doc/whatsnew/3.3.rst
@@ -254,6 +254,9 @@ inspection of exception attributes::
PEP 380: Syntax for Delegating to a Subgenerator
================================================
+:pep:`380` - Syntax for Delegating to a Subgenerator
+ PEP written by Greg Ewing.
+
PEP 380 adds the ``yield from`` expression, allowing a generator to delegate
part of its operations to another generator. This allows a section of code
containing 'yield' to be factored out and placed in another generator.
@@ -267,6 +270,67 @@ Kelly and Nick Coghlan, documentation by Zbigniew Jędrzejewski-Szmek and
Nick Coghlan)
+PEP 409: Suppressing exception context
+======================================
+
+:pep:`409` - Suppressing exception context
+ PEP written by Ethan Furman, implemented by Ethan Furman and Nick Coghlan.
+
+PEP 409 introduces new syntax that allows the display of the chained
+exception context to be disabled. This allows cleaner error messages in
+applications that convert between exception types::
+
+ >>> class D:
+ ... def __init__(self, extra):
+ ... self._extra_attributes = extra
+ ... def __getattr__(self, attr):
+ ... try:
+ ... return self._extra_attributes[attr]
+ ... except KeyError:
+ ... raise AttributeError(attr) from None
+ ...
+ >>> D({}).x
+ Traceback (most recent call last):
+ File "<stdin>", line 1, in <module>
+ File "<stdin>", line 8, in __getattr__
+ AttributeError: x
+
+Without the ``from None`` suffix to suppress the cause, the original
+exception would be displayed by default::
+
+ >>> class C:
+ ... def __init__(self, extra):
+ ... self._extra_attributes = extra
+ ... def __getattr__(self, attr):
+ ... try:
+ ... return self._extra_attributes[attr]
+ ... except KeyError:
+ ... raise AttributeError(attr)
+ ...
+ >>> C({}).x
+ Traceback (most recent call last):
+ File "<stdin>", line 6, in __getattr__
+ KeyError: 'x'
+
+ During handling of the above exception, another exception occurred:
+
+ Traceback (most recent call last):
+ File "<stdin>", line 1, in <module>
+ File "<stdin>", line 8, in __getattr__
+ AttributeError: x
+
+No debugging capability is lost, as the original exception context remains
+available if needed (for example, if an intervening library has incorrectly
+suppressed valuable underlying details)::
+
+ >>> try:
+ ... D({}).x
+ ... except AttributeError as exc:
+ ... print(repr(exc.__context__))
+ ...
+ KeyError('x',)
+
+
PEP 3155: Qualified name for classes and functions
==================================================