From 08ae41180a38cc4ae6a13f4543df4f2306103930 Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Wed, 13 Dec 2023 18:44:24 -0800 Subject: [PATCH 1/7] Print colorized exception just like built-in traceback in pdb --- Lib/pdb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/pdb.py b/Lib/pdb.py index 83b7fefec63636..46648802f52e18 100755 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -2232,7 +2232,7 @@ def main(): print("The program exited via sys.exit(). Exit status:", end=' ') print(e) except BaseException as e: - traceback.print_exc() + traceback._print_exception_bltin(e) print("Uncaught exception. Entering post mortem debugging") print("Running 'cont' or 'step' will restart the program") pdb.interaction(None, e) From 8dc8917542e4874b510339fb60e45b470334d30c Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Thu, 14 Dec 2023 02:51:40 +0000 Subject: [PATCH 2/7] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2023-12-14-02-51-38.gh-issue-113081.S-9Qyn.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2023-12-14-02-51-38.gh-issue-113081.S-9Qyn.rst diff --git a/Misc/NEWS.d/next/Library/2023-12-14-02-51-38.gh-issue-113081.S-9Qyn.rst b/Misc/NEWS.d/next/Library/2023-12-14-02-51-38.gh-issue-113081.S-9Qyn.rst new file mode 100644 index 00000000000000..e6b2d01837c7df --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-12-14-02-51-38.gh-issue-113081.S-9Qyn.rst @@ -0,0 +1 @@ +Print colorized exception just like built-in traceback in :mod:`pdb` From cb23014324d472a2c8fece09e7e4582f669090d5 Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Fri, 3 May 2024 18:40:48 -0700 Subject: [PATCH 3/7] Update Lib/pdb.py Co-authored-by: Brandt Bucher --- Lib/pdb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/pdb.py b/Lib/pdb.py index 46648802f52e18..756a290750b0e3 100755 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -2232,7 +2232,7 @@ def main(): print("The program exited via sys.exit(). Exit status:", end=' ') print(e) except BaseException as e: - traceback._print_exception_bltin(e) + traceback._print_exception_bltin(e, colorize=_colorize.can_colorize()) print("Uncaught exception. Entering post mortem debugging") print("Running 'cont' or 'step' will restart the program") pdb.interaction(None, e) From f5fe947cfed18ed22a69bef6512ab0ef81a86439 Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Fri, 3 May 2024 18:47:36 -0700 Subject: [PATCH 4/7] Revert the change --- Lib/pdb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/pdb.py b/Lib/pdb.py index 9ff02703456d0e..98e8b3b3e3e436 100755 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -2303,7 +2303,7 @@ def main(): print("The program exited via sys.exit(). Exit status:", end=' ') print(e) except BaseException as e: - traceback._print_exception_bltin(e, colorize=_colorize.can_colorize()) + traceback._print_exception_bltin(e) print("Uncaught exception. Entering post mortem debugging") print("Running 'cont' or 'step' will restart the program") pdb.interaction(None, e) From 781ec37c2f10ce9d2be55a851967e8432b583278 Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Fri, 3 May 2024 18:53:29 -0700 Subject: [PATCH 5/7] Use print_exception instead of a private interface --- Lib/pdb.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/pdb.py b/Lib/pdb.py index 98e8b3b3e3e436..b9dee13c87bdfa 100755 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -84,6 +84,7 @@ import tokenize import traceback import linecache +import _colorize from contextlib import contextmanager from rlcompleter import Completer @@ -2303,7 +2304,7 @@ def main(): print("The program exited via sys.exit(). Exit status:", end=' ') print(e) except BaseException as e: - traceback._print_exception_bltin(e) + traceback.print_exception(e, colorize=_colorize.can_colorize()) print("Uncaught exception. Entering post mortem debugging") print("Running 'cont' or 'step' will restart the program") pdb.interaction(None, e) From 1a21f416032bae724f344cefc8414e519aeb4e02 Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Fri, 3 May 2024 22:13:26 -0700 Subject: [PATCH 6/7] Force not colorize on the failing test --- Lib/test/test_pdb.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 5635d17c99d2a3..edc52f02116cd3 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -14,7 +14,7 @@ from contextlib import ExitStack, redirect_stdout from io import StringIO from test import support -from test.support import os_helper +from test.support import force_not_colorized, os_helper from test.support.import_helper import import_module from test.support.pty_helper import run_pty, FakeInput from unittest.mock import patch @@ -2918,6 +2918,7 @@ def start_pdb(): self.assertNotIn(b'Error', stdout, "Got an error running test script under PDB") + @force_not_colorized def test_issue16180(self): # A syntax error in the debuggee. script = "def f: pass\n" From 8a6e6131131729cffb4bfe8836bea64fc5c66a64 Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Fri, 3 May 2024 23:37:04 -0700 Subject: [PATCH 7/7] Fix another color test --- Lib/test/test_pdb.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index edc52f02116cd3..4d57b0f849b5bb 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -2932,6 +2932,7 @@ def test_issue16180(self): 'Fail to handle a syntax error in the debuggee.' .format(expected, stderr)) + @force_not_colorized def test_issue84583(self): # A syntax error from ast.literal_eval should not make pdb exit. script = "import ast; ast.literal_eval('')\n"