summaryrefslogtreecommitdiffstats
path: root/Lib/traceback.py
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2012-05-15 05:09:31 (GMT)
committerBenjamin Peterson <benjamin@python.org>2012-05-15 05:09:31 (GMT)
commitd5a1c44455d969968f453f029727bfc45e4ce0a9 (patch)
tree98e91aa8130d600df0b1fdf329bbdc9d60d4b14c /Lib/traceback.py
parentd91dc623791fd9973b914a57540d89cb986da7c9 (diff)
downloadcpython-d5a1c44455d969968f453f029727bfc45e4ce0a9.zip
cpython-d5a1c44455d969968f453f029727bfc45e4ce0a9.tar.gz
cpython-d5a1c44455d969968f453f029727bfc45e4ce0a9.tar.bz2
PEP 415: Implement suppression of __context__ display with an exception attribute
This replaces the original PEP 409 implementation. See #14133.
Diffstat (limited to 'Lib/traceback.py')
-rw-r--r--Lib/traceback.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/Lib/traceback.py b/Lib/traceback.py
index 35858af..eeb9e73 100644
--- a/Lib/traceback.py
+++ b/Lib/traceback.py
@@ -119,15 +119,16 @@ def _iter_chain(exc, custom_tb=None, seen=None):
seen = set()
seen.add(exc)
its = []
+ context = exc.__context__
cause = exc.__cause__
- if cause is Ellipsis:
- context = exc.__context__
- if context is not None and context not in seen:
- its.append(_iter_chain(context, None, seen))
- its.append([(_context_message, None)])
- elif cause is not None and cause not in seen:
+ if cause is not None and cause not in seen:
its.append(_iter_chain(cause, False, seen))
its.append([(_cause_message, None)])
+ elif (context is not None and
+ not exc.__suppress_context__ and
+ context not in seen):
+ its.append(_iter_chain(context, None, seen))
+ its.append([(_context_message, None)])
its.append([(exc, custom_tb or exc.__traceback__)])
# itertools.chain is in an extension module and may be unavailable
for it in its: