FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

GH-142928: Add deprecation warning for removal of `color` on `HelpFormatter` by savannahostrowski · Pull Request #142946 · python/cpython · GitHub

/ cpython Public
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) .rst  (2) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
6 changes: 6 additions & 0 deletions Doc/whatsnew/3.15.rst
Show comments Show annotations View file Open in desktop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
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

Back | FazBrowse Home | New Git URL