Repository navigation
GH-139862: Remove color from HelpFormatter - #142274
Conversation
|
(Updated from |
…BfsD4.rst Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
|
This PR broke instantiating the formatter outside the parser because import argparse
formatter = argparse.HelpFormatter(prog="program")
formatter.add_usage(usage=None, actions=[], groups=[])
print(formatter.format_help())This now raises an Traceback (most recent call last):
File "/tmp/t.py", line 5, in <module>
print(formatter.format_help())
~~~~~~~~~~~~~~~~~~~~~^^
File "/tmp/argparse.py", line 303, in format_help
help = self._root_section.format_help()
File "/tmp/argparse.py", line 228, in format_help
item_help = join([func(*args) for func, args in self.items])
~~~~^^^^^^^
File "/tmp/argparse.py", line 315, in _format_usage
t = self._theme
^^^^^^^^^^^
AttributeError: 'HelpFormatter' object has no attribute '_theme'This only broke a test over at https://github.com/hamdanal/rich-argparse and I am not sure if it a supported usage of the formatter. Let me know if I need to create an issue/PR. |
|
Hey @hamdanal, thanks for raising this! Direct instantiation of |
|
@hamdanal And thank you for testing the nightly and reporting so quickly :) |
This is broken with cpython main which removed the color keyword argument to HelperFormatter in python/cpython#142274
This is broken with cpython main which removed the color keyword argument to HelperFormatter in python/cpython#142274
This is broken with cpython main which removed the color keyword argument to HelperFormatter in python/cpython#142274
|
Beware, this also breaks existing code that sets the color this way. This was possible in 3.14 and now it explodes: Python 3.14.2 (main, Dec 5 2025, 00:00:00) [GCC 15.2.1 20251111 (Red Hat 15.2.1-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import argparse
>>> argparse.HelpFormatter(prog='', color=True)
<argparse.HelpFormatter object at 0x7fd998cd1400>Python 3.15.0a3 (main, Dec 16 2025, 00:00:00) [GCC 15.2.1 20251211 (Red Hat 15.2.1-5)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import argparse
>>> argparse.HelpFormatter(prog='', color=True)
Traceback (most recent call last):
File "<python-input-1>", line 1, in <module>
argparse.HelpFormatter(prog='', color=True)
~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
TypeError: HelpFormatter.__init__() got an unexpected keyword argument 'color'In particular, this breaks pypa/build before pypa/build#962 |
|
Reported as #142928, so it is trackable. |
agentgrep runs on Python 3.15, which becomes the default interpreter and the version CI tests. On 3.15 every command, `--version` included, failed with `TypeError: HelpFormatter.__init__() got an unexpected keyword argument 'color'`: the themed formatter forwarded `color=True` to `argparse.HelpFormatter`, and 3.15 removed that keyword (python/cpython#142274). The published release crashed the same way under a bare `uvx agentgrep`, which uv 0.13 runs on 3.15 (#168). - **Formatter fix**: the class `create_themed_formatter()` returns binds its theme as a class attribute instead of overriding `__init__`; argparse builds the formatter as `formatter_class(prog=...)` on 3.14 and 3.15 and applies color afterwards. - **Tests**: `tests/test_help_color.py` renders `--help` with color forced on and off; it fails on 3.15 without the fix. - **Python 3.15 default**: `.tool-versions` lists 3.15 first, the test matrix runs 3.15 in place of 3.14, and the release job builds on 3.15. - **Packaging**: the trove classifiers add Python 3.15, so PyPI lists it as supported. - **Dependabot**: override `katex` to `^0.18.2` in the docs pnpm workspace for GHSA-238p-pmpm-9mq7 until mermaid-cli 12 brings katex ^0.18; mermaid still renders flowcharts and `$$` labels. - **Changelog**: a Fixes entry, "agentgrep runs on Python 3.15". Fixes #168
After digging into this, I think that we should just remove color from being passed into HelpFormatter, since this never worked and was never documented. IMO, this should be controlled by the parser anyway.
argparseformatter handling ofcolor#139862