https://github.com/python/cpython/commit/dc9f2385ed528caf4ab02965b6d3e16b8a72db25
commit: dc9f2385ed528caf4ab02965b6d3e16b8a72db25
branch: main
author: Savannah Ostrowski <[email protected]>
committer: savannahostrowski <[email protected]>
date: 2025-12-07T21:02:12Z
summary:

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

files:
M Lib/argparse.py
M Lib/test/test_argparse.py

diff --git a/Lib/argparse.py b/Lib/argparse.py
index 6ed7386d0dd407..398825508f5917 100644
--- a/Lib/argparse.py
+++ b/Lib/argparse.py
@@ -189,6 +189,8 @@ def __init__(
         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
 
diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py
index fe5232e9f3b591..7c5eed21219de0 100644
--- a/Lib/test/test_argparse.py
+++ b/Lib/test/test_argparse.py
@@ -5694,6 +5694,11 @@ def custom_formatter(prog):
                 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

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to