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>
This commit is contained in:
Pablo Galindo Salgado 2024-05-05 21:32:23 +02:00 committed by GitHub
parent 40cc809902
commit f27f8c790a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
41 changed files with 5328 additions and 170 deletions

View file

@ -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