gh-118893: Evaluate all statements in the new REPL separately (#119318)

Co-authored-by: Łukasz Langa <lukasz@langa.pl>
This commit is contained in:
Pablo Galindo Salgado 2024-05-21 19:16:56 -04:00 committed by GitHub
parent 9fa206aaec
commit a3e4fec873
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 128 additions and 9 deletions

View file

@ -94,7 +94,7 @@ class InteractiveInterpreter:
except:
self.showtraceback()
def showsyntaxerror(self, filename=None):
def showsyntaxerror(self, filename=None, **kwargs):
"""Display the syntax error that just occurred.
This doesn't display a stack trace because there isn't one.
@ -106,6 +106,7 @@ class InteractiveInterpreter:
The output is written by self.write(), below.
"""
colorize = kwargs.pop('colorize', False)
type, value, tb = sys.exc_info()
sys.last_exc = value
sys.last_type = type
@ -123,7 +124,7 @@ class InteractiveInterpreter:
value = SyntaxError(msg, (filename, lineno, offset, line))
sys.last_exc = sys.last_value = value
if sys.excepthook is sys.__excepthook__:
lines = traceback.format_exception_only(type, value)
lines = traceback.format_exception_only(type, value, colorize=colorize)
self.write(''.join(lines))
else:
# If someone has set sys.excepthook, we let that take precedence