Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Doc/whatsnew/3.15.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,12 @@
New deprecations
----------------

* :mod:`argparse`:

* The *color* parameter of :class:`~argparse.HelpFormatter` is deprecated.

Check warning on line 1083 in Doc/whatsnew/3.15.rst

View workflow job for this annotation

GitHub Actions / Docs / Docs

py:class reference target not found: argparse.HelpFormatter [ref.class]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's undocumented, fix the Sphinx warning:

Suggested change
* The *color* parameter of :class:`~argparse.HelpFormatter` is deprecated.
* The *color* parameter of :class:`!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
Expand Down
10 changes: 10 additions & 0 deletions Lib/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,17 @@ def __init__(
indent_increment=2,
max_help_position=24,
width=None,
color=None,
):
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
Expand Down
6 changes: 6 additions & 0 deletions Lib/test/test_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
# =====================================
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Deprecate :class:`~argparse.HelpFormatter`'s *color* parameter. Users should use the *color* parameter on :class:`~argparse.ArgumentParser` instead.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Deprecate :class:`~argparse.HelpFormatter`'s *color* parameter. Users should use the *color* parameter on :class:`~argparse.ArgumentParser` instead.
Deprecate :class:`!HelpFormatter`'s *color* parameter. Use the *color* parameter on :class:`~argparse.ArgumentParser` instead.

Loading