From 69ecb4c234b6aa6f2863e8282526264a1f7942ba Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Tue, 9 Dec 2025 09:22:26 -0800 Subject: [PATCH] [3.14] GH-139946: Document argparse includes color codes when redirecting to stderr to file (#142398) Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> --- Doc/library/argparse.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index b8ecbf3e5846..f64ace037f69 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -644,6 +644,13 @@ variables and terminal capabilities. However, if ``color=False``, colored output is always disabled, even if environment variables like ``FORCE_COLOR`` are set. +.. note:: + + Error messages will include color codes when redirecting stderr to a + file. To avoid this, set the |NO_COLOR|_ or :envvar:`PYTHON_COLORS` + environment variable (for example, + ``NO_COLOR=1 python script.py 2> errors.txt``). + .. versionadded:: 3.14 -- 2.47.3