]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-139862: Fix direct instantiation of `HelpFormatter` (#142384)
authorSavannah Ostrowski <savannah@python.org>
Sun, 7 Dec 2025 21:02:12 +0000 (13:02 -0800)
committerGitHub <noreply@github.com>
Sun, 7 Dec 2025 21:02:12 +0000 (21:02 +0000)
Lib/argparse.py
Lib/test/test_argparse.py

index 6ed7386d0dd4071dc44a039a6e1d755e229cf1d7..398825508f59171f36345e852a0809b66a5fb9d5 100644 (file)
@@ -189,6 +189,8 @@ class HelpFormatter(object):
         self._whitespace_matcher = _re.compile(r'\s+', _re.ASCII)
         self._long_break_matcher = _re.compile(r'\n\n\n+')
 
+        self._set_color(False)
+
     def _set_color(self, color):
         from _colorize import can_colorize, decolor, get_theme
 
index fe5232e9f3b591b55c9e80839c9ef0e0765bcd02..7c5eed21219de0454474fc649880edec0a1c7ce3 100644 (file)
@@ -5694,6 +5694,11 @@ class TestHelpCustomHelpFormatter(TestCase):
                 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