Skip to content

Commit 00da0af

Browse files
gh-113081: Print colorized exception just like built-in traceback in pdb (#113082)
1 parent 85af789 commit 00da0af

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

Lib/pdb.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
import tokenize
8585
import traceback
8686
import linecache
87+
import _colorize
8788

8889
from contextlib import contextmanager
8990
from rlcompleter import Completer
@@ -2347,7 +2348,7 @@ def main():
23472348
print("The program exited via sys.exit(). Exit status:", end=' ')
23482349
print(e)
23492350
except BaseException as e:
2350-
traceback.print_exc()
2351+
traceback.print_exception(e, colorize=_colorize.can_colorize())
23512352
print("Uncaught exception. Entering post mortem debugging")
23522353
print("Running 'cont' or 'step' will restart the program")
23532354
pdb.interaction(None, e)

Lib/test/test_pdb.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from contextlib import ExitStack, redirect_stdout
1616
from io import StringIO
1717
from test import support
18-
from test.support import os_helper
18+
from test.support import force_not_colorized, os_helper
1919
from test.support.import_helper import import_module
2020
from test.support.pty_helper import run_pty, FakeInput
2121
from unittest.mock import patch
@@ -2919,6 +2919,7 @@ def start_pdb():
29192919
self.assertNotIn(b'Error', stdout,
29202920
"Got an error running test script under PDB")
29212921

2922+
@force_not_colorized
29222923
def test_issue16180(self):
29232924
# A syntax error in the debuggee.
29242925
script = "def f: pass\n"
@@ -2932,6 +2933,7 @@ def test_issue16180(self):
29322933
'Fail to handle a syntax error in the debuggee.'
29332934
.format(expected, stderr))
29342935

2936+
@force_not_colorized
29352937
def test_issue84583(self):
29362938
# A syntax error from ast.literal_eval should not make pdb exit.
29372939
script = "import ast; ast.literal_eval('')\n"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Print colorized exception just like built-in traceback in :mod:`pdb`

0 commit comments

Comments
 (0)