Skip to content

Commit dc9f238

Browse files
GH-139862: Fix direct instantiation of HelpFormatter (#142384)
1 parent f193c8f commit dc9f238

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

Lib/argparse.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ def __init__(
189189
self._whitespace_matcher = _re.compile(r'\s+', _re.ASCII)
190190
self._long_break_matcher = _re.compile(r'\n\n\n+')
191191

192+
self._set_color(False)
193+
192194
def _set_color(self, color):
193195
from _colorize import can_colorize, decolor, get_theme
194196

Lib/test/test_argparse.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5694,6 +5694,11 @@ def custom_formatter(prog):
56945694
a-very-long-command command that does something
56955695
'''))
56965696

5697+
def test_direct_formatter_instantiation(self):
5698+
formatter = argparse.HelpFormatter(prog="program")
5699+
formatter.add_usage(usage=None, actions=[], groups=[])
5700+
help_text = formatter.format_help()
5701+
self.assertEqual(help_text, "usage: program\n")
56975702

56985703
# =====================================
56995704
# Optional/Positional constructor tests

0 commit comments

Comments
 (0)