From c51fbbd2505a84b627e1d065e061ee2bac477707 Mon Sep 17 00:00:00 2001 From: M Bussonnier Date: Mon, 3 Nov 2025 09:08:14 +0100 Subject: [PATCH] Clarify that patch_stdout also redirect stderr It was not super clear to me, and triggered a minor issue in a project, where logs in non-interactive mode were redirected to stdout as well. --- src/prompt_toolkit/patch_stdout.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/prompt_toolkit/patch_stdout.py b/src/prompt_toolkit/patch_stdout.py index e1f2a7a2c..47da77939 100644 --- a/src/prompt_toolkit/patch_stdout.py +++ b/src/prompt_toolkit/patch_stdout.py @@ -40,7 +40,7 @@ @contextmanager def patch_stdout(raw: bool = False) -> Generator[None, None, None]: """ - Replace `sys.stdout` by an :class:`_StdoutProxy` instance. + Replace `sys.stdout` and `sys.stderr` by an :class:`_StdoutProxy` instance. Writing to this proxy will make sure that the text appears above the prompt, and that it doesn't destroy the output from the renderer. If no @@ -52,6 +52,9 @@ def patch_stdout(raw: bool = False) -> Generator[None, None, None]: is changed. Printing to stdout will be scheduled in the event loop that's active when the context manager is created. + Warning: In order for all text to appear above the prompt `stderr` will also + be redirected to the stdout proxy. + :param raw: (`bool`) When True, vt100 terminal escape sequences are not removed/escaped. """