mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
gh-121804: Always show error location for SyntaxError's in new repl (#121886)
This commit is contained in:
parent
e077b201f4
commit
354d55eb1f
5 changed files with 36 additions and 10 deletions
|
@ -161,6 +161,9 @@ 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, **kwargs):
|
||||
super().showsyntaxerror(**kwargs)
|
||||
|
||||
def _excepthook(self, typ, value, tb):
|
||||
import traceback
|
||||
lines = traceback.format_exception(
|
||||
|
@ -173,7 +176,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
|
||||
|
@ -190,10 +193,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