Repository navigation
The new REPL outputs different tracebeck when custom sys.excepthook is used #122478
Copy link
Copy link
Closed
Labels
topic-replRelated to the interactive shellRelated to the interactive shelltype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or errortopic-replRelated to the interactive shellRelated to the interactive shell
on Jul 30, 2024 And for compile-time errors:
>>> ? File "<unknown>", line 1 ? ^ SyntaxError: invalid syntax >>> import sys; sys.excepthook = lambda *args: sys.__excepthook__(*args) >>> ? Traceback (most recent call last): File "/home/serhiy/py/cpython/Lib/_pyrepl/console.py", line 172, in runsource tree = ast.parse(source) File "/home/serhiy/py/cpython/Lib/ast.py", line 53, in parse return compile(source, filename, mode, flags, _feature_version=feature_version, optimize=optimize) File "<unknown>", line 1 ? ^ SyntaxError: invalid syntax
Seems to be done on purpose in
code.InteractiveInterpreter.showsyntaxerror:
Lines 126 to 132 in bd3d31f
if sys.excepthook is sys.__excepthook__: lines = traceback.format_exception_only(type, value, colorize=colorize) self.write(''.join(lines)) else: # If someone has set sys.excepthook, we let that take precedence # over self.write self._call_excepthook(type, value, tb) I suppose this could be overridden in _pyrepl to always output with
.write()?- changed the title
[-]The new REPL outputs different tracebeck when custom sys.systemhook is used[/-][+]The new REPL outputs different tracebeck when custom sys.excepthook is used[/+]on Jul 31, 2024 sys.excepthookis of course called on purpose, but the traceback was not corrected for it. Andsys.last_tracebackwas not always correct even with the defaultsys.excepthook.@serhiy-storchaka, can this be closed?
Reacted by Serhiy Storchaka
Metadata
Metadata
Assignees
Labels
topic-replRelated to the interactive shellRelated to the interactive shelltype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Bug report
If
sys.systemhookis notsys.__systemhook__, the new REPL outputs the line in the code module in the traceback:>>> xxx Traceback (most recent call last): File "<python-input-0>", line 1, in <module> xxx NameError: name 'xxx' is not defined >>> import sys; sys.excepthook = lambda *args: sys.__excepthook__(*args) >>> xxx Traceback (most recent call last): File "/home/serhiy/py/cpython/Lib/code.py", line 91, in runcode exec(code, self.locals) ~~~~^^^^^^^^^^^^^^^^^^^ File "<python-input-2>", line 1, in <module> xxx NameError: name 'xxx' is not definedLinked PRs