GH-139862: Fix direct instantiation of HelpFormatter (#142384)

This commit is contained in:
Savannah Ostrowski 2025-12-07 13:02:12 -08:00 committed by GitHub
parent f193c8fe9e
commit dc9f2385ed
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 0 deletions

View file

@ -189,6 +189,8 @@ def __init__(
self._whitespace_matcher = _re.compile(r'\s+', _re.ASCII) self._whitespace_matcher = _re.compile(r'\s+', _re.ASCII)
self._long_break_matcher = _re.compile(r'\n\n\n+') self._long_break_matcher = _re.compile(r'\n\n\n+')
self._set_color(False)
def _set_color(self, color): def _set_color(self, color):
from _colorize import can_colorize, decolor, get_theme from _colorize import can_colorize, decolor, get_theme

View file

@ -5694,6 +5694,11 @@ def custom_formatter(prog):
a-very-long-command command that does something a-very-long-command command that does something
''')) '''))
def test_direct_formatter_instantiation(self):
formatter = argparse.HelpFormatter(prog="program")
formatter.add_usage(usage=None, actions=[], groups=[])
help_text = formatter.format_help()
self.assertEqual(help_text, "usage: program\n")
# ===================================== # =====================================
# Optional/Positional constructor tests # Optional/Positional constructor tests