diff --git a/Lib/_pydecimal.py b/Lib/_pydecimal.py --- a/Lib/_pydecimal.py +++ b/Lib/_pydecimal.py @@ -4108,7 +4108,7 @@ >>> context.create_decimal_from_float(3.1415926535897932) Traceback (most recent call last): ... - decimal.Inexact: None + decimal.Inexact """ d = Decimal.from_float(f) # An exact conversion diff --git a/Lib/code.py b/Lib/code.py --- a/Lib/code.py +++ b/Lib/code.py @@ -140,32 +140,15 @@ sys.last_type, sys.last_value, last_tb = ei = sys.exc_info() sys.last_traceback = last_tb try: - lines = [] - for value, tb in traceback._iter_chain(*ei[1:]): - if isinstance(value, str): - lines.append(value) - lines.append('\n') - continue - if 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)) + lines = traceback.format_exception(ei[0], ei[1], last_tb.tb_next) + 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(ei[0], ei[1], last_tb) finally: - tblist = 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) + last_tb = ei = None def write(self, data): """Write a string. diff --git a/Lib/traceback.py b/Lib/traceback.py --- a/Lib/traceback.py +++ b/Lib/traceback.py @@ -92,7 +92,7 @@ if file is None: file = sys.stderr 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="") @@ -106,7 +106,7 @@ printed as does print_exception(). """ 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):