]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-113081: Print colorized exception just like built-in traceback in pdb (#113082)
authorTian Gao <gaogaotiantian@hotmail.com>
Sat, 4 May 2024 10:26:40 +0000 (03:26 -0700)
committerGitHub <noreply@github.com>
Sat, 4 May 2024 10:26:40 +0000 (12:26 +0200)
Lib/pdb.py
Lib/test/test_pdb.py
Misc/NEWS.d/next/Library/2023-12-14-02-51-38.gh-issue-113081.S-9Qyn.rst [new file with mode: 0644]

index bb669a0d2c1ce563d7085e58ddf146bf49ce7acf..e6450861328b280245668dd3c84585525df2333f 100755 (executable)
@@ -84,6 +84,7 @@ import inspect
 import tokenize
 import traceback
 import linecache
+import _colorize
 
 from contextlib import contextmanager
 from rlcompleter import Completer
@@ -2347,7 +2348,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(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)
index a3d2dda43b086d9400b715b0554a993e5609494a..c9ea52717490b1d86ac9375f2cf19816fdd7b962 100644 (file)
@@ -15,7 +15,7 @@ import zipapp
 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
@@ -2919,6 +2919,7 @@ def bœr():
         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"
@@ -2932,6 +2933,7 @@ def bœr():
             '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"
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 (file)
index 0000000..e6b2d01
--- /dev/null
@@ -0,0 +1 @@
+Print colorized exception just like built-in traceback in :mod:`pdb`