Skip to content

gh-122622: Add PyREPL simple_interact.statement_submitted_hook - #157241

Open
edvilme wants to merge 9 commits into
python:mainfrom
edvilme:pyrepl-hook
Open

edvilme wants to merge 9 commits into
python:mainfrom
edvilme:pyrepl-hook

Conversation

@edvilme

@edvilme edvilme commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Supersedes #144724

Adds a statement_submitted_hook hook to _pyrepl.simple_interact that 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 (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)

image

With error reporting

image

@brettcannon
brettcannon self-requested a review September 17, 2026 21:15
Comment thread Lib/_pyrepl/__init__.py Outdated
Comment thread Lib/_pyrepl/simple_interact.py Outdated
Comment thread Lib/_pyrepl/simple_interact.py Outdated
Comment thread Lib/_pyrepl/simple_interact.py Outdated
Comment thread Lib/_pyrepl/simple_interact.py Outdated
@bedevere-app

bedevere-app Bot commented Sep 17, 2026

Copy link
Copy Markdown

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. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

Comment thread Lib/_pyrepl/simple_interact.py Outdated
@edvilme edvilme changed the title gh-122622: Add PyREPL pre_execution_hook gh-122622: Add PyREPL simple_interact.statement_submitted_hook Sep 19, 2026
@edvilme

edvilme commented Sep 19, 2026

Copy link
Copy Markdown
Contributor Author

I have made the requested changes; please review again

@bedevere-app

bedevere-app Bot commented Sep 19, 2026

Copy link
Copy Markdown

Thanks for making the requested changes!

@brettcannon: please review the changes made to this pull request.

@bedevere-app
bedevere-app Bot requested a review from brettcannon September 19, 2026 01:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants