Skip to content
Prev Previous commit
Next Next commit
Merge branch 'main' into gh-82378-fix-tracebacklimit-in-pyrepl
  • Loading branch information
cfbolz committed Aug 16, 2024
commit b741cb49f56ed78142ee3d07fbd712147acf0438
58 changes: 20 additions & 38 deletions Lib/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,30 +108,21 @@ def showsyntaxerror(self, filename=None, **kwargs):
"""
colorize = kwargs.pop('colorize', False)
limit = kwargs.pop('limit', None)
type, value, tb = sys.exc_info()
sys.last_exc = value
sys.last_type = type
sys.last_value = value
sys.last_traceback = tb
if filename and type is SyntaxError:
# Work hard to stuff the correct filename in the exception
try:
msg, (dummy_filename, lineno, offset, line) = value.args
except ValueError:
# Not the format we expect; leave it alone
pass
else:
# Stuff in the right filename
value = SyntaxError(msg, (filename, lineno, offset, line))
sys.last_exc = sys.last_value = value
if sys.excepthook is sys.__excepthook__:
lines = traceback.format_exception_only(type, value, colorize=colorize,
limit=limit)
self.write(''.join(lines))
else:
# If someone has set sys.excepthook, we let that take precedence
# over self.write
self._call_excepthook(type, value, tb)
try:
typ, value, tb = sys.exc_info()
if filename and typ is SyntaxError:
# Work hard to stuff the correct filename in the exception
try:
msg, (dummy_filename, lineno, offset, line) = value.args
except ValueError:
# Not the format we expect; leave it alone
pass
else:
# Stuff in the right filename
value = SyntaxError(msg, (filename, lineno, offset, line))
self._showtraceback(typ, value, None, colorize, limit)
finally:
typ = value = tb = None

def showtraceback(self, **kwargs):
"""Display the exception that just occurred.
Expand All @@ -143,29 +134,20 @@ def showtraceback(self, **kwargs):
"""
colorize = kwargs.pop('colorize', False)
limit = kwargs.pop('limit', None)
sys.last_type, sys.last_value, last_tb = ei = sys.exc_info()
sys.last_traceback = last_tb
sys.last_exc = ei[1]
try:
if sys.excepthook is sys.__excepthook__:
lines = traceback.format_exception(
ei[0], ei[1], last_tb.tb_next, colorize=colorize,
limit=limit)
self.write(''.join(lines))
else:
# If someone has set sys.excepthook, we let that take precedence
# over self.write
self._call_excepthook(ei[0], ei[1], last_tb)
typ, value, tb = sys.exc_info()
self._showtraceback(typ, value, tb.tb_next, colorize, limit)
finally:
typ = value = tb = None

def _showtraceback(self, typ, value, tb, colorize):
def _showtraceback(self, typ, value, tb, colorize, limit):
sys.last_type = typ
sys.last_traceback = tb
sys.last_exc = sys.last_value = value = value.with_traceback(tb)
if sys.excepthook is sys.__excepthook__:
lines = traceback.format_exception(typ, value, tb,
colorize=colorize)
colorize=colorize,
limit=limit)
self.write(''.join(lines))
Comment thread
cfbolz marked this conversation as resolved.
Outdated
else:
# If someone has set sys.excepthook, we let that take precedence
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.