diff options
author | Sergey B Kirpichev <skirpichev@gmail.com> | 2024-08-19 14:19:23 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-19 14:19:23 (GMT) |
commit | 354d55eb1fa40f272419aa6459ee5d2c4804c8ea (patch) | |
tree | abbaa973e79116edc5ec40cf7ab6501c37560a87 /Lib/_pyrepl | |
parent | e077b201f49a6007ddad7c1b6e3069a037b6d952 (diff) | |
download | cpython-354d55eb1fa40f272419aa6459ee5d2c4804c8ea.zip cpython-354d55eb1fa40f272419aa6459ee5d2c4804c8ea.tar.gz cpython-354d55eb1fa40f272419aa6459ee5d2c4804c8ea.tar.bz2 |
gh-121804: Always show error location for SyntaxError's in new repl (#121886)
Diffstat (limited to 'Lib/_pyrepl')
-rw-r--r-- | Lib/_pyrepl/console.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/Lib/_pyrepl/console.py b/Lib/_pyrepl/console.py index 2b6c6be..330ebbd 100644 --- a/Lib/_pyrepl/console.py +++ b/Lib/_pyrepl/console.py @@ -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: |