Skip to content
Prev Previous commit
Next Next commit
Address feedback
  • Loading branch information
edvilme committed Sep 19, 2026
commit 6d7dfe0f41bd65765d02af68a39134569430920d
9 changes: 5 additions & 4 deletions Lib/_pyrepl/simple_interact.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@
from .readline import _get_reader, multiline_input, append_history_file


# Called after the user submits a Python statement, but before it is executed.
# The hook is not called for PyREPL commands such as ``clear``. Exceptions raised
# by the hook and its return value are ignored. External tools such as IDEs can
# install a hook to augment the behavior of the REPL.
# Called with the complete statement, which may span multiple lines, after the
# user submits it but before it is executed. The hook is not called for PyREPL
# commands such as ``clear``. Exceptions raised by the hook and its return value
# are ignored. External tools such as IDEs can install a hook to augment the
# behavior of the REPL.
#
# For example, VS Code can mark the start of command execution:
#
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_pyrepl/test_interact.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ def fake_multiline_input(more_lines, ps1, ps2):
return output.getvalue(), console.locals

def test_hook_called_before_statement_execution(self):
statement = "print('statement executed')"
statement = "if True:\n print('statement executed')\n"
escape_sequence = "\x1b]633;C\x07"
hook = MagicMock(
side_effect=lambda statement: print(escape_sequence, end="")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Add an optional ``_pyrepl.pre_execution_hook`` callable that is invoked with
the submitted source before each interactive statement is executed. This
allows external tools to implement features such as shell integration.
Add an optional ``_pyrepl.simple_interact.statement_submitted_hook`` callback
that runs after a complete statement is submitted and before it is executed,
allowing external tools to implement features such as shell integration.
Loading