Skip to content

Commit d82b48c

Browse files
Add deprecation warning for color
1 parent 92243dc commit d82b48c

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

Lib/argparse.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,18 @@ def __init__(
166166
indent_increment=2,
167167
max_help_position=24,
168168
width=None,
169+
color=None,
169170
):
171+
# Handle deprecated 'color' parameter for backwards compatibility
172+
if color is not None:
173+
import warnings
174+
warnings.warn(
175+
"The 'color' parameter is deprecated. "
176+
"Set 'color' in ArgumentParser instead.",
177+
DeprecationWarning,
178+
stacklevel=2,
179+
)
180+
170181
# default setting for width
171182
if width is None:
172183
import shutil

Lib/test/test_argparse.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5702,6 +5702,12 @@ def test_direct_formatter_instantiation(self):
57025702
help_text = formatter.format_help()
57035703
self.assertEqual(help_text, "usage: program\n")
57045704

5705+
def test_formatter_color_parameter_deprecated(self):
5706+
with self.assertWarns(DeprecationWarning) as cm:
5707+
argparse.HelpFormatter(prog="program", color=True)
5708+
self.assertIn("'color' parameter is deprecated", str(cm.warning))
5709+
self.assertIn("ArgumentParser", str(cm.warning))
5710+
57055711
# =====================================
57065712
# Optional/Positional constructor tests
57075713
# =====================================

0 commit comments

Comments
 (0)