Skip to content

Commit 4ccf8c0

Browse files
committed
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.
1 parent 4819ced commit 4ccf8c0

3 files changed

Lines changed: 17 additions & 28 deletions

File tree

Lib/_pydecimal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4108,7 +4108,7 @@ def create_decimal_from_float(self, f):
41084108
>>> context.create_decimal_from_float(3.1415926535897932)
41094109
Traceback (most recent call last):
41104110
...
4111-
decimal.Inexact: None
4111+
decimal.Inexact
41124112
41134113
"""
41144114
d = Decimal.from_float(f) # An exact conversion

Lib/code.py

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -140,32 +140,15 @@ def showtraceback(self):
140140
sys.last_type, sys.last_value, last_tb = ei = sys.exc_info()
141141
sys.last_traceback = last_tb
142142
try:
143-
lines = []
144-
for value, tb in traceback._iter_chain(*ei[1:]):
145-
if isinstance(value, str):
146-
lines.append(value)
147-
lines.append('\n')
148-
continue
149-
if tb:
150-
tblist = traceback.extract_tb(tb)
151-
if tb is last_tb:
152-
# The last traceback includes the frame we
153-
# exec'd in
154-
del tblist[:1]
155-
tblines = traceback.format_list(tblist)
156-
if tblines:
157-
lines.append("Traceback (most recent call last):\n")
158-
lines.extend(tblines)
159-
lines.extend(traceback.format_exception_only(type(value),
160-
value))
143+
lines = traceback.format_exception(ei[0], ei[1], last_tb.tb_next)
144+
if sys.excepthook is sys.__excepthook__:
145+
self.write(''.join(lines))
146+
else:
147+
# If someone has set sys.excepthook, we let that take precedence
148+
# over self.write
149+
sys.excepthook(ei[0], ei[1], last_tb)
161150
finally:
162-
tblist = last_tb = ei = None
163-
if sys.excepthook is sys.__excepthook__:
164-
self.write(''.join(lines))
165-
else:
166-
# If someone has set sys.excepthook, we let that take precedence
167-
# over self.write
168-
sys.excepthook(type, value, last_tb)
151+
last_tb = ei = None
169152

170153
def write(self, data):
171154
"""Write a string.

Lib/traceback.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,13 @@ def print_exception(etype, value, tb, limit=None, file=None, chain=True):
8989
occurred with a caret on the next line indicating the approximate
9090
position of the error.
9191
"""
92+
# format_exception has ignored etype for some time, and code such as cgitb
93+
# passes in bogus values as a result. For compatibility with such code we
94+
# ignore it here (rather than in the new TracebackException API).
9295
if file is None:
9396
file = sys.stderr
9497
for line in TracebackException(
95-
etype, value, tb, limit=limit).format(chain=chain):
98+
type(value), value, tb, limit=limit).format(chain=chain):
9699
print(line, file=file, end="")
97100

98101

@@ -105,8 +108,11 @@ def format_exception(etype, value, tb, limit=None, chain=True):
105108
these lines are concatenated and printed, exactly the same text is
106109
printed as does print_exception().
107110
"""
111+
# format_exception has ignored etype for some time, and code such as cgitb
112+
# passes in bogus values as a result. For compatibility with such code we
113+
# ignore it here (rather than in the new TracebackException API).
108114
return list(TracebackException(
109-
etype, value, tb, limit=limit).format(chain=chain))
115+
type(value), value, tb, limit=limit).format(chain=chain))
110116

111117

112118
def format_exception_only(etype, value):

0 commit comments

Comments
 (0)