Skip to content

Commit 5385096

Browse files
committed
Since Python 3.10 (see pythonGH-22610) format_exception_only only uses exc_value
1 parent 70925bb commit 5385096

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

Lib/pdb.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,7 @@ def user_exception(self, frame, exc_info):
377377
# stop when the debuggee is returning from such generators.
378378
prefix = 'Internal ' if (not exc_traceback
379379
and exc_type is StopIteration) else ''
380-
self.message('%s%s' % (prefix,
381-
traceback.format_exception_only(exc_type, exc_value)[-1].strip()))
380+
self.message('%s%s' % (prefix, self._format_exc(exc_value)))
382381
self.interaction(frame, exc_traceback)
383382

384383
# General interaction function
@@ -851,7 +850,7 @@ def checkexpr(self, expr):
851850
try:
852851
compile(expr, "<stdin>", "eval")
853852
except SyntaxError as exc:
854-
return _rstr(traceback.format_exception_only(exc)[-1].strip())
853+
return _rstr(self._format_exc(exc))
855854
return None
856855

857856
def do_enable(self, arg):
@@ -1267,12 +1266,11 @@ def _getval_except(self, arg, frame=None):
12671266
else:
12681267
return eval(arg, frame.f_globals, frame.f_locals)
12691268
except BaseException as exc:
1270-
err = traceback.format_exception_only(exc)[-1].strip()
1271-
return _rstr('** raised %s **' % err)
1269+
return _rstr('** raised %s **' % self._format_exc(exc))
12721270

12731271
def _error_exc(self):
1274-
exc_info = sys.exc_info()[:2]
1275-
self.error(traceback.format_exception_only(*exc_info)[-1].strip())
1272+
exc = sys.exc_info()[1]
1273+
self.error(self._format_exc(exc))
12761274

12771275
def _msg_val_func(self, arg, func):
12781276
try:
@@ -1664,6 +1662,9 @@ def _run(self, target: Union[_ModuleTarget, _ScriptTarget]):
16641662

16651663
self.run(target.code)
16661664

1665+
def _format_exc(self, exc: BaseException):
1666+
return traceback.format_exception_only(exc)[-1].strip()
1667+
16671668

16681669
# Collect all command help into docstring, if not run with -OO
16691670

0 commit comments

Comments
 (0)