--- a PPN by Garber Painting Akron. With Image Size Reduction included!URL: http://github.com/python/cpython/pull/136809.patch
color=True)
+ ... color=False)
>>> parser.add_argument('--action', choices=['sum', 'max'])
>>> parser.add_argument('integers', metavar='N', type=int, nargs='+',
... help='an integer for the accumulator')
>>> parser.parse_args(['--help'])
-Even if a CLI author has enabled color, it can be
+Even if a CLI author has not disabled color, it can be
:ref:`controlled using environment variables `.
-If you're writing code that needs to be compatible with older Python versions
-and want to opportunistically use ``color`` when it's available, you
-can set it as an attribute after initializing the parser instead of using the
-keyword argument::
-
- >>> parser = argparse.ArgumentParser(description='Process some integers.')
- >>> parser.color = True
-
.. versionadded:: 3.14
diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst
index c108a94692dca7..0ec3ed88874efc 100644
--- a/Doc/whatsnew/3.14.rst
+++ b/Doc/whatsnew/3.14.rst
@@ -1204,11 +1204,10 @@ argparse
.. _whatsnew314-color-argparse:
-* Introduced the optional *color* parameter to
- :class:`argparse.ArgumentParser`, enabling color for help text.
- This can be controlled by :ref:`environment variables
- `. Color has also been enabled for help in the
- :ref:`stdlib CLIs ` which use :mod:`!argparse`.
+* Enable color for help text, which can be disabled with the optional *color*
+ parameter to :class:`argparse.ArgumentParser`.
+ This can also be controlled by :ref:`environment variables
+ `.
(Contributed by Hugo van Kemenade in :gh:`130645`.)
diff --git a/Misc/NEWS.d/next/Library/2025-07-19-16-20-54.gh-issue-130645.O-dYcN.rst b/Misc/NEWS.d/next/Library/2025-07-19-16-20-54.gh-issue-130645.O-dYcN.rst
new file mode 100644
index 00000000000000..bc32482770597b
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-07-19-16-20-54.gh-issue-130645.O-dYcN.rst
@@ -0,0 +1 @@
+Default to color help in argparse.
From dddcd65c04e26d2974e361253b8095e10254ab63 Mon Sep 17 00:00:00 2001
From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Date: Sat, 19 Jul 2025 16:47:19 +0200
Subject: [PATCH 4/7] Update tests
---
Lib/test/test_argparse.py | 2 ++
Lib/test/test_clinic.py | 1 +
2 files changed, 3 insertions(+)
diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py
index 7e356d3ae3fdd1..fc73174d98cd6f 100644
--- a/Lib/test/test_argparse.py
+++ b/Lib/test/test_argparse.py
@@ -6049,6 +6049,7 @@ def test_argument_error(self):
class TestArgumentTypeError(TestCase):
+ @force_not_colorized
def test_argument_type_error(self):
def spam(string):
@@ -7013,6 +7014,7 @@ def test_os_error(self):
self.parser.parse_args, ['@no-such-file'])
+@force_not_colorized_test_class
class TestProgName(TestCase):
source = textwrap.dedent('''\
import argparse
diff --git a/Lib/test/test_clinic.py b/Lib/test/test_clinic.py
index e83114794519d5..b1a81cfc1b124f 100644
--- a/Lib/test/test_clinic.py
+++ b/Lib/test/test_clinic.py
@@ -2792,6 +2792,7 @@ def test_cli_verbose(self):
out = self.expect_success("-v", fn)
self.assertEqual(out.strip(), fn)
+ @support.force_not_colorized
def test_cli_help(self):
out = self.expect_success("-h")
self.assertIn("usage: clinic.py", out)
From b5c0d881b497f4e6455cf3fdadcd100eae549077 Mon Sep 17 00:00:00 2001
From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Date: Sat, 19 Jul 2025 18:19:12 +0300
Subject: [PATCH 5/7] Fix wording
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Co-authored-by: Ćukasz Langa
---
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 87993f88813d4a..b80c00e9eecba5 100644
--- a/Doc/library/argparse.rst
+++ b/Doc/library/argparse.rst
@@ -620,7 +620,7 @@ keyword argument::
color
^^^^^
-By default, the help message is printed in color. If you want to plain text
+By default, the help message is printed in color. If you want plain text
help messages, you can disable it by setting ``color`` to ``False``::
>>> parser = argparse.ArgumentParser(description='Process some integers.',
From 82c7e2511c631ab9dfb7a031bd078a27296233fa Mon Sep 17 00:00:00 2001
From: Adam Turner <9087854+aa-turner@users.noreply.github.com>
Date: Sat, 19 Jul 2025 17:32:07 +0200
Subject: [PATCH 6/7] Improve description of disabling colour support locally
vs in the ArgumentParser
---
Doc/library/argparse.rst | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst
index b80c00e9eecba5..ed603171102fe1 100644
--- a/Doc/library/argparse.rst
+++ b/Doc/library/argparse.rst
@@ -620,8 +620,11 @@ keyword argument::
color
^^^^^
-By default, the help message is printed in color. If you want plain text
-help messages, you can disable it by setting ``color`` to ``False``::
+By default, the help message is printed in color using `ANSI escape sequences
+`__.
+If you want plain text help messages, you can disable this :ref:`in your local
+environment `, or in the argument parser itself
+by setting ``color`` to ``False``::
>>> parser = argparse.ArgumentParser(description='Process some integers.',
... color=False)
@@ -630,9 +633,6 @@ help messages, you can disable it by setting ``color`` to ``False``::
... help='an integer for the accumulator')
>>> parser.parse_args(['--help'])
-Even if a CLI author has not disabled color, it can be
-:ref:`controlled using environment variables `.
-
.. versionadded:: 3.14
From 0abf68e3264d4953517edbd40856805761c5dc15 Mon Sep 17 00:00:00 2001
From: Adam Turner <9087854+aa-turner@users.noreply.github.com>
Date: Sat, 19 Jul 2025 17:40:47 +0200
Subject: [PATCH 7/7] Add a cross-reference to NEWS
---
.../next/Library/2025-07-19-16-20-54.gh-issue-130645.O-dYcN.rst | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Misc/NEWS.d/next/Library/2025-07-19-16-20-54.gh-issue-130645.O-dYcN.rst b/Misc/NEWS.d/next/Library/2025-07-19-16-20-54.gh-issue-130645.O-dYcN.rst
index bc32482770597b..96e076dfe5bd12 100644
--- a/Misc/NEWS.d/next/Library/2025-07-19-16-20-54.gh-issue-130645.O-dYcN.rst
+++ b/Misc/NEWS.d/next/Library/2025-07-19-16-20-54.gh-issue-130645.O-dYcN.rst
@@ -1 +1 @@
-Default to color help in argparse.
+Enable color help by default in :mod:`argparse`.
pFad - Phonifier reborn
Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy