summaryrefslogtreecommitdiffstats
path: root/Lib/traceback.py
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2021-12-03 22:01:15 (GMT)
committerGitHub <noreply@github.com>2021-12-03 22:01:15 (GMT)
commit5bb7ef2768be5979b306e4c7552862b1746c251d (patch)
tree2c5d4d96a1e5bba8d0d918cc413d882f10308e63 /Lib/traceback.py
parentd9301703fb1086cafbd730c17e3d450a192485d6 (diff)
downloadcpython-5bb7ef2768be5979b306e4c7552862b1746c251d.zip
cpython-5bb7ef2768be5979b306e4c7552862b1746c251d.tar.gz
cpython-5bb7ef2768be5979b306e4c7552862b1746c251d.tar.bz2
bpo-45607: Make it possible to enrich exception displays via setting their __note__ field (GH-29880)
Diffstat (limited to 'Lib/traceback.py')
-rw-r--r--Lib/traceback.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/Lib/traceback.py b/Lib/traceback.py
index 77f8590..b244750 100644
--- a/Lib/traceback.py
+++ b/Lib/traceback.py
@@ -685,6 +685,8 @@ class TracebackException:
# Capture now to permit freeing resources: only complication is in the
# unofficial API _format_final_exc_line
self._str = _some_str(exc_value)
+ self.__note__ = exc_value.__note__ if exc_value else None
+
if exc_type and issubclass(exc_type, SyntaxError):
# Handle SyntaxError's specially
self.filename = exc_value.filename
@@ -816,6 +818,8 @@ class TracebackException:
yield _format_final_exc_line(stype, self._str)
else:
yield from self._format_syntax_error(stype)
+ if self.__note__ is not None:
+ yield from [l + '\n' for l in self.__note__.split('\n')]
def _format_syntax_error(self, stype):
"""Format SyntaxError exceptions (internal helper)."""