mirror of
https://github.com/python/cpython.git
synced 2025-07-09 20:35:26 +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
|
@ -64,7 +64,7 @@ class InteractiveInterpreter:
|
|||
code = self.compile(source, filename, symbol)
|
||||
except (OverflowError, SyntaxError, ValueError):
|
||||
# Case 1
|
||||
self.showsyntaxerror(filename)
|
||||
self.showsyntaxerror(filename, source=source)
|
||||
return False
|
||||
|
||||
if code is None:
|
||||
|
@ -123,6 +123,12 @@ class InteractiveInterpreter:
|
|||
# Stuff in the right filename
|
||||
value = SyntaxError(msg, (filename, lineno, offset, line))
|
||||
sys.last_exc = sys.last_value = value
|
||||
# Set the line of text that the exception refers to
|
||||
source = kwargs.pop('source', '')
|
||||
lines = source.splitlines()
|
||||
if (source and type is SyntaxError
|
||||
and not value.text and len(lines) >= value.lineno):
|
||||
value.text = lines[value.lineno - 1]
|
||||
if sys.excepthook is sys.__excepthook__:
|
||||
lines = traceback.format_exception_only(type, value, colorize=colorize)
|
||||
self.write(''.join(lines))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue