[3.13] gh-121804: Always show error location for SyntaxError's in new repl (GH-121886) (#123148)

(cherry picked from commit 354d55eb1f)
This commit is contained in:
Sergey B Kirpichev 2024-08-19 22:01:58 +03:00 committed by GitHub
parent 21399a0963
commit c8f4069ab1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 29 additions and 7 deletions

View file

@ -161,8 +161,8 @@ class InteractiveColoredConsole(code.InteractiveConsole):
super().__init__(locals=locals, filename=filename, local_exit=local_exit) # type: ignore[call-arg]
self.can_colorize = _colorize.can_colorize()
def showsyntaxerror(self, filename=None):
super().showsyntaxerror(colorize=self.can_colorize)
def showsyntaxerror(self, filename=None, **kwargs):
super().showsyntaxerror(colorize=self.can_colorize, **kwargs)
def showtraceback(self):
super().showtraceback(colorize=self.can_colorize)
@ -171,7 +171,7 @@ class InteractiveColoredConsole(code.InteractiveConsole):
try:
tree = ast.parse(source)
except (SyntaxError, OverflowError, ValueError):
self.showsyntaxerror(filename)
self.showsyntaxerror(filename, source=source)
return False
if tree.body:
*_, last_stmt = tree.body
@ -188,10 +188,10 @@ class InteractiveColoredConsole(code.InteractiveConsole):
f"Try the asyncio REPL ({python} -m asyncio) to use"
f" top-level 'await' and run background asyncio tasks."
)
self.showsyntaxerror(filename)
self.showsyntaxerror(filename, source=source)
return False
except (OverflowError, ValueError):
self.showsyntaxerror(filename)
self.showsyntaxerror(filename, source=source)
return False
if code is None: