From 24ab7995f507e4f25e3d793908458f7231050b98 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Mon, 6 Jan 2020 05:21:36 +0100 Subject: [PATCH] bpo-39228: traceback.FrameSummary: handle error via repr --- Lib/traceback.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Lib/traceback.py b/Lib/traceback.py index 7a4c8e19f98..c13de709de2 100644 --- a/Lib/traceback.py +++ b/Lib/traceback.py @@ -257,7 +257,17 @@ class FrameSummary: self._line = line if lookup_line: self.line - self.locals = {k: repr(v) for k, v in locals.items()} if locals else None + if locals: + self.locals = {} + for k, v in locals.items(): + try: + self.locals[k] = repr(v) + except (KeyboardInterrupt, SystemExit): + raise + except BaseException as exc: + self.locals[k] = f"" + else: + self.locals = None def __eq__(self, other): if isinstance(other, FrameSummary):