diff options
author | Pablo Galindo Salgado <Pablogsal@gmail.com> | 2024-05-05 19:32:23 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-05 19:32:23 (GMT) |
commit | f27f8c790af1233d499b795af1c0d1b36aaecaf5 (patch) | |
tree | 22c502c6382512fafbb63e3020c8462e5400d4df /Lib/code.py | |
parent | 40cc809902304f60c6e1c933191dd4d64e570e28 (diff) | |
download | cpython-f27f8c790af1233d499b795af1c0d1b36aaecaf5.zip cpython-f27f8c790af1233d499b795af1c0d1b36aaecaf5.tar.gz cpython-f27f8c790af1233d499b795af1c0d1b36aaecaf5.tar.bz2 |
gh-111201: A new Python REPL (GH-111567)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
Co-authored-by: Marta Gómez Macías <mgmacias@google.com>
Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
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 |