From d82b48c3a8e402244763e3f891585b9cb55f3abe Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Thu, 18 Dec 2025 09:06:07 -0800 Subject: [PATCH 1/4] Add deprecation warning for color --- Lib/argparse.py | 11 +++++++++++ Lib/test/test_argparse.py | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/Lib/argparse.py b/Lib/argparse.py index 633fec69ea4615..48c7206db95437 100644 --- a/Lib/argparse.py +++ b/Lib/argparse.py @@ -166,7 +166,18 @@ def __init__( indent_increment=2, max_help_position=24, width=None, + color=None, ): + # Handle deprecated 'color' parameter for backwards compatibility + if color is not None: + import warnings + warnings.warn( + "The 'color' parameter is deprecated. " + "Set 'color' in ArgumentParser instead.", + DeprecationWarning, + stacklevel=2, + ) + # default setting for width if width is None: import shutil diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py index 758af98d5cb046..2a53bd8f12e681 100644 --- a/Lib/test/test_argparse.py +++ b/Lib/test/test_argparse.py @@ -5702,6 +5702,12 @@ def test_direct_formatter_instantiation(self): help_text = formatter.format_help() self.assertEqual(help_text, "usage: program\n") + def test_formatter_color_parameter_deprecated(self): + with self.assertWarns(DeprecationWarning) as cm: + argparse.HelpFormatter(prog="program", color=True) + self.assertIn("'color' parameter is deprecated", str(cm.warning)) + self.assertIn("ArgumentParser", str(cm.warning)) + # ===================================== # Optional/Positional constructor tests # ===================================== From cf98ebc4c8b9ab609bb64f1bb9f281296ab88600 Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Thu, 18 Dec 2025 09:07:02 -0800 Subject: [PATCH 2/4] Cleanup --- Lib/argparse.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Lib/argparse.py b/Lib/argparse.py index 48c7206db95437..059bfe9aad8a9d 100644 --- a/Lib/argparse.py +++ b/Lib/argparse.py @@ -168,7 +168,6 @@ def __init__( width=None, color=None, ): - # Handle deprecated 'color' parameter for backwards compatibility if color is not None: import warnings warnings.warn( From 42e5f31e0d5b90fe6c04ff56d1695e2db952fdb8 Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Thu, 18 Dec 2025 09:11:30 -0800 Subject: [PATCH 3/4] Add to whats new --- Doc/whatsnew/3.15.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst index 7e032fe5df2fdf..7f9298de1213b2 100644 --- a/Doc/whatsnew/3.15.rst +++ b/Doc/whatsnew/3.15.rst @@ -1078,6 +1078,12 @@ Deprecated New deprecations ---------------- +* :mod:`argparse`: + + * The *color* parameter of :class:`~argparse.HelpFormatter` is deprecated. + Use the *color* parameter of :class:`~argparse.ArgumentParser` instead. + (Contributed by Savannah Ostrowski in :gh:`142946`.) + * CLI: * Deprecate :option:`-b` and :option:`!-bb` command-line options From 0333f0e3dfaf792ee0004f203ad8a1647bf40982 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Thu, 18 Dec 2025 17:13:15 +0000 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2025-12-18-17-13-10.gh-issue-142928.bcgx78.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2025-12-18-17-13-10.gh-issue-142928.bcgx78.rst diff --git a/Misc/NEWS.d/next/Library/2025-12-18-17-13-10.gh-issue-142928.bcgx78.rst b/Misc/NEWS.d/next/Library/2025-12-18-17-13-10.gh-issue-142928.bcgx78.rst new file mode 100644 index 00000000000000..6ea580784c0a2f --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-12-18-17-13-10.gh-issue-142928.bcgx78.rst @@ -0,0 +1 @@ +Deprecate :class:`~argparse.HelpFormatter`'s *color* parameter. Users should use the *color* parameter on :class:`~argparse.ArgumentParser` instead.