mirror of
https://github.com/python/cpython.git
synced 2025-07-28 05:34:31 +00:00
[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:
parent
21399a0963
commit
c8f4069ab1
5 changed files with 29 additions and 7 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue