Repository navigation
Conversation
Co-authored-by: Anthony Kim <anthonykim@microsoft.com>
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
|
I have made the requested changes; please review again |
|
Thanks for making the requested changes! @brettcannon: please review the changes made to this pull request. |
|
@pablogsal @ambv feel free to review, but if you're too busy I will just plan to merge in about a week. |
|
Hello, when you have the chance, can I please get another review here? @pablogsal @ambv @johnslavik |
|
@edvilme Could you please use your own words when replying? Thanks |
| console.write("Error in statement_submitted_hook:\n") | ||
| console._excepthook(type(exc), exc, exc.__traceback__) |
There was a problem hiding this comment.
_excepthook writes to console directly, but it would make sense to me if we reused sys.excepthook like _showtraceback, just without writing to sys attributes. Maybe add a param to showtraceback and _showtraceback for REPL-specific errors to just avoid writing to sys attributes but go through the traceback display pipeline inside _showtraceback? Or simply move the pipeline to _excepthook, since no call sites (other than _showtraceback) use _excepthook directly
WDYT @pablogsal?
I've included `test_keyboard_interrupt_preserves_last_exception` as an invariant test, inspired by a catch in pythonGH-157241.
Supersedes #144724
Adds a
statement_submitted_hookhook to_pyrepl.simple_interactthat gets triggered after the user has submitted a statement (not necessarily a line) but before it is executed.Rationale
This should be configurable by external tools such as IDEs who may want to perform an action before a statement is executed, such as displaying custom escape sequences for terminal integration, handling custom logging logic, performing analysis, etc.
This hook should allow said tools to perform an action.
Example (Timer)
Example (VSCode)
VS Code uses custom escape sequences to indicate when a command execution has started and finished. Here, the hook could be used to print an invisible escape sequence to the terminal. (Note that the example uses
### EXEC ###to represent it visually, but escape sequences are invisible)With error reporting
AI Usage
AI was used to help with merge conflicts