Skip to content

[3.15] gh-152907: Restore cooked output flags around the input hook in the new REPL (GH-153389) - #158112

Merged
pablogsal merged 1 commit into
python:3.15from
miss-islington:backport-46ee358-3.15
Sep 24, 2026
Merged

pablogsal merged 1 commit into
python:3.15from
miss-islington:backport-46ee358-3.15

Conversation

@miss-islington

Copy link
Copy Markdown
Contributor

pyrepl clears OPOST for its own cursor rendering but calls PyOS_InputHook
from inside the raw-mode read loop, so output written by an input hook
(GUI toolkit event loops, and any warning/traceback/print they emit) is
emitted with bare '\n' and no '\r'. Restore the terminal's saved output
flags around the hook call and re-enter raw mode afterwards; only oflag is
toggled so ECHO/ICANON stay off at the prompt.

  • Skip the input-hook test on platforms without pty devices

The Emscripten buildbot has the pty module but no pty devices, so
pty.openpty() raises OSError("out of pty devices"). Guard the test
class the same way Lib/test/test_pty.py does.

  • Propagate the input hook's return value and drop the sleep from the test

Co-Authored-By: Claude Fable 5 noreply@anthropic.com

  • Trim comments

Co-Authored-By: Claude Fable 5 noreply@anthropic.com

  • Observe the hook's output synchronously instead of via the reader thread

The reader thread no longer feeds any assertion: the hook drains the pty
master itself, so the check is an exact comparison. A drainer is still
needed for restore(), which writes before switching modes.


(cherry picked from commit 46ee358)

Co-authored-by: Harjoth Khara harjoth.khara@gmail.com
Co-authored-by: Claude Fable 5 noreply@anthropic.com

… the new REPL (pythonGH-153389)

* pythongh-152907: Restore cooked output flags around the input hook in the new REPL

pyrepl clears OPOST for its own cursor rendering but calls PyOS_InputHook
from inside the raw-mode read loop, so output written by an input hook
(GUI toolkit event loops, and any warning/traceback/print they emit) is
emitted with bare '\n' and no '\r'.  Restore the terminal's saved output
flags around the hook call and re-enter raw mode afterwards; only oflag is
toggled so ECHO/ICANON stay off at the prompt.

* Skip the input-hook test on platforms without pty devices

The Emscripten buildbot has the pty module but no pty devices, so
pty.openpty() raises OSError("out of pty devices").  Guard the test
class the same way Lib/test/test_pty.py does.

* Propagate the input hook's return value and drop the sleep from the test

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* Trim comments

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* Observe the hook's output synchronously instead of via the reader thread

The reader thread no longer feeds any assertion: the hook drains the pty
master itself, so the check is an exact comparison. A drainer is still
needed for restore(), which writes before switching modes.

---------
(cherry picked from commit 46ee358)

Co-authored-by: Harjoth Khara <harjoth.khara@gmail.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants