diff options
Diffstat (limited to 'Lib/code.py')
-rw-r--r-- | Lib/code.py | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/Lib/code.py b/Lib/code.py index f4aecdd..1ee1ad6 100644 --- a/Lib/code.py +++ b/Lib/code.py @@ -130,7 +130,7 @@ class InteractiveInterpreter: # over self.write sys.excepthook(type, value, tb) - def showtraceback(self): + def showtraceback(self, **kwargs): """Display the exception that just occurred. We remove the first stack item because it is our own code. @@ -138,11 +138,12 @@ class InteractiveInterpreter: The output is written by self.write(), below. """ + colorize = kwargs.pop('colorize', False) sys.last_type, sys.last_value, last_tb = ei = sys.exc_info() sys.last_traceback = last_tb sys.last_exc = ei[1] try: - lines = traceback.format_exception(ei[0], ei[1], last_tb.tb_next) + lines = traceback.format_exception(ei[0], ei[1], last_tb.tb_next, colorize=colorize) if sys.excepthook is sys.__excepthook__: self.write(''.join(lines)) else: @@ -170,7 +171,7 @@ class InteractiveConsole(InteractiveInterpreter): """ - def __init__(self, locals=None, filename="<console>", local_exit=False): + def __init__(self, locals=None, filename="<console>", *, local_exit=False): """Constructor. The optional locals argument will be passed to the @@ -280,7 +281,7 @@ class InteractiveConsole(InteractiveInterpreter): elif exitmsg != '': self.write('%s\n' % exitmsg) - def push(self, line): + def push(self, line, filename=None): """Push a line to the interpreter. The line should not have a trailing newline; it may have @@ -296,7 +297,9 @@ class InteractiveConsole(InteractiveInterpreter): """ self.buffer.append(line) source = "\n".join(self.buffer) - more = self.runsource(source, self.filename) + if filename is None: + filename = self.filename + more = self.runsource(source, filename) if not more: self.resetbuffer() return more |