Remaining fallout from 17911
The code module was using a private function from traceback in order to skip a frame - used the direct interface to do that instead, The decimal module suffered minor fallout from formatting changes ('None' as a value is now not printed by traceback, the same as None was not before). The cgitb module was passing a bogus exception type (type.__name__) into format_exception, which uncovered that format_exception and print_exception had been ignoring the etype for some time, so the compatibility thunk to the new code now does the same thing.
This commit is contained in:
parent
3737e600f4
commit
2f0441f03f
|
@ -4108,7 +4108,7 @@ class Context(object):
|
||||||
>>> context.create_decimal_from_float(3.1415926535897932)
|
>>> context.create_decimal_from_float(3.1415926535897932)
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
...
|
...
|
||||||
decimal.Inexact: None
|
decimal.Inexact
|
||||||
|
|
||||||
"""
|
"""
|
||||||
d = Decimal.from_float(f) # An exact conversion
|
d = Decimal.from_float(f) # An exact conversion
|
||||||
|
|
33
Lib/code.py
33
Lib/code.py
|
@ -140,32 +140,15 @@ class InteractiveInterpreter:
|
||||||
sys.last_type, sys.last_value, last_tb = ei = sys.exc_info()
|
sys.last_type, sys.last_value, last_tb = ei = sys.exc_info()
|
||||||
sys.last_traceback = last_tb
|
sys.last_traceback = last_tb
|
||||||
try:
|
try:
|
||||||
lines = []
|
lines = traceback.format_exception(ei[0], ei[1], last_tb.tb_next)
|
||||||
for value, tb in traceback._iter_chain(*ei[1:]):
|
if sys.excepthook is sys.__excepthook__:
|
||||||
if isinstance(value, str):
|
self.write(''.join(lines))
|
||||||
lines.append(value)
|
else:
|
||||||
lines.append('\n')
|
# If someone has set sys.excepthook, we let that take precedence
|
||||||
continue
|
# over self.write
|
||||||
if tb:
|
sys.excepthook(ei[0], ei[1], last_tb)
|
||||||
tblist = traceback.extract_tb(tb)
|
|
||||||
if tb is last_tb:
|
|
||||||
# The last traceback includes the frame we
|
|
||||||
# exec'd in
|
|
||||||
del tblist[:1]
|
|
||||||
tblines = traceback.format_list(tblist)
|
|
||||||
if tblines:
|
|
||||||
lines.append("Traceback (most recent call last):\n")
|
|
||||||
lines.extend(tblines)
|
|
||||||
lines.extend(traceback.format_exception_only(type(value),
|
|
||||||
value))
|
|
||||||
finally:
|
finally:
|
||||||
tblist = last_tb = ei = None
|
last_tb = ei = None
|
||||||
if sys.excepthook is sys.__excepthook__:
|
|
||||||
self.write(''.join(lines))
|
|
||||||
else:
|
|
||||||
# If someone has set sys.excepthook, we let that take precedence
|
|
||||||
# over self.write
|
|
||||||
sys.excepthook(type, value, last_tb)
|
|
||||||
|
|
||||||
def write(self, data):
|
def write(self, data):
|
||||||
"""Write a string.
|
"""Write a string.
|
||||||
|
|
|
@ -89,10 +89,13 @@ def print_exception(etype, value, tb, limit=None, file=None, chain=True):
|
||||||
occurred with a caret on the next line indicating the approximate
|
occurred with a caret on the next line indicating the approximate
|
||||||
position of the error.
|
position of the error.
|
||||||
"""
|
"""
|
||||||
|
# format_exception has ignored etype for some time, and code such as cgitb
|
||||||
|
# passes in bogus values as a result. For compatibility with such code we
|
||||||
|
# ignore it here (rather than in the new TracebackException API).
|
||||||
if file is None:
|
if file is None:
|
||||||
file = sys.stderr
|
file = sys.stderr
|
||||||
for line in TracebackException(
|
for line in TracebackException(
|
||||||
etype, value, tb, limit=limit).format(chain=chain):
|
type(value), value, tb, limit=limit).format(chain=chain):
|
||||||
print(line, file=file, end="")
|
print(line, file=file, end="")
|
||||||
|
|
||||||
|
|
||||||
|
@ -105,8 +108,11 @@ def format_exception(etype, value, tb, limit=None, chain=True):
|
||||||
these lines are concatenated and printed, exactly the same text is
|
these lines are concatenated and printed, exactly the same text is
|
||||||
printed as does print_exception().
|
printed as does print_exception().
|
||||||
"""
|
"""
|
||||||
|
# format_exception has ignored etype for some time, and code such as cgitb
|
||||||
|
# passes in bogus values as a result. For compatibility with such code we
|
||||||
|
# ignore it here (rather than in the new TracebackException API).
|
||||||
return list(TracebackException(
|
return list(TracebackException(
|
||||||
etype, value, tb, limit=limit).format(chain=chain))
|
type(value), value, tb, limit=limit).format(chain=chain))
|
||||||
|
|
||||||
|
|
||||||
def format_exception_only(etype, value):
|
def format_exception_only(etype, value):
|
||||||
|
|
Loading…
Reference in New Issue