From c4fb950aa90ed90df262dc928dc217e1b5126e9a Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Sun, 7 Dec 2025 19:54:19 -0800 Subject: [PATCH 1/3] Document workaround for argparse stderr to file --- Doc/library/argparse.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index b8ecbf3e584630..d30c44dd8fdad9 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -644,6 +644,12 @@ 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 :envvar:`NO_COLOR` or :envvar:`PYTHON_COLORS` + environment variable (e.g., ``NO_COLOR=1 python script.py 2> errors.txt``). + .. versionadded:: 3.14 From 7e0a7adaa5c41e37f36ac7e004a1a613a3767df8 Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Sun, 7 Dec 2025 20:14:22 -0800 Subject: [PATCH 2/3] Fix NO_COLOR --- Doc/library/argparse.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index d30c44dd8fdad9..86776ac7181501 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -647,7 +647,7 @@ are set. .. note:: Error messages will include color codes when redirecting stderr to a - file. To avoid this, set the :envvar:`NO_COLOR` or :envvar:`PYTHON_COLORS` + file. To avoid this, set the |NO_COLOR|_ or :envvar:`PYTHON_COLORS` environment variable (e.g., ``NO_COLOR=1 python script.py 2> errors.txt``). .. versionadded:: 3.14 From d1958163759d9778b406404b0eb2c6d295b6c717 Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Tue, 9 Dec 2025 09:16:52 -0800 Subject: [PATCH 3/3] Update Doc/library/argparse.rst Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> --- Doc/library/argparse.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index 86776ac7181501..f64ace037f6975 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -648,7 +648,8 @@ are set. 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 (e.g., ``NO_COLOR=1 python script.py 2> errors.txt``). + environment variable (for example, + ``NO_COLOR=1 python script.py 2> errors.txt``). .. versionadded:: 3.14