[3.13] gh-118893: Evaluate all statements in the new REPL separately (GH-119318) (#119408)

(cherry picked from commit a3e4fec873)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
This commit is contained in:
Miss Islington (bot) 2024-05-22 18:22:01 +02:00 committed by GitHub
parent eafd633fac
commit a463cd8e45
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