Mercurial > cpython-lru_cache-weakref
diff Lib/code.py @ 78672:a812de69b493
Issue #12643: Respect sys.excepthook in code.InteractiveConsole
| author | Nick Coghlan <ncoghlan@gmail.com> |
|---|---|
| date | Mon, 20 Aug 2012 23:02:28 +1000 |
| parents | 0db67153d25f |
| children | 8d28d44f3a9a |
line wrap: on
line diff
--- a/Lib/code.py Mon Aug 20 14:42:59 2012 +0200 +++ b/Lib/code.py Mon Aug 20 23:02:28 2012 +1000 @@ -105,9 +105,10 @@ The output is written by self.write(), below. """ - type, value, sys.last_traceback = sys.exc_info() + type, value, tb = sys.exc_info() 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: @@ -119,8 +120,13 @@ # Stuff in the right filename value = SyntaxError(msg, (filename, lineno, offset, line)) sys.last_value = value - lines = traceback.format_exception_only(type, value) - self.write(''.join(lines)) + if sys.excepthook is sys.__excepthook__: + lines = traceback.format_exception_only(type, value) + self.write(''.join(lines)) + else: + # If someone has set sys.excepthook, we let that take precedence + # over self.write + sys.excepthook(type, value, tb) def showtraceback(self): """Display the exception that just occurred. @@ -143,7 +149,12 @@ lines.extend(traceback.format_exception_only(type, value)) finally: tblist = tb = None - self.write(''.join(lines)) + 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, tb) def write(self, data): """Write a string.
