From 140361ad0a344243f181514111057a02e6fb4209 Mon Sep 17 00:00:00 2001 From: Peter Holloway Date: Fri, 9 Jan 2026 14:30:01 +0000 Subject: [PATCH] Only display exception context if __suppress_context__ not set The built-in repl only displays the context of an exception (the "During the handling of the above exception..." message) if __suppress_context__ is not set, eg by using raise Exception() from xyz This makes ptpython behave the same way. See description of default behaviour in the python docs: https://docs.python.org/3/library/exceptions.html#BaseException.__suppress_context__ --- src/ptpython/printer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ptpython/printer.py b/src/ptpython/printer.py index a3578de..b589143 100644 --- a/src/ptpython/printer.py +++ b/src/ptpython/printer.py @@ -327,7 +327,7 @@ def _format_exception_output( "", "\nThe above exception was the direct cause of the following exception:\n\n", ) - elif e.__context__: + elif e.__context__ and not e.__suppress_context__: yield from self._format_exception_output(e.__context__, highlight=highlight) yield ( "",