FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

GH-139862: Remove `color` from HelpFormatter by savannahostrowski · Pull Request #142274 · python/cpython · GitHub

/ cpython Public

GH-139862: Remove color from HelpFormatter - #142274

Merged
savannahostrowski merged 5 commits into
python:mainfrom
savannahostrowski:remove-formatter-color
Dec 5, 2025
Merged

GH-139862: Remove color from HelpFormatter#142274
savannahostrowski merged 5 commits into
python:mainfrom
savannahostrowski:remove-formatter-color

Conversation

savannahostrowski commented Dec 4, 2025
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Member

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.

hugovk commented Dec 5, 2025

Copy link
Copy Markdown
Member

(Updated from main to fix the Android failure: #142289)

savannahostrowski and others added 2 commits December 5, 2025 07:48
…BfsD4.rst

Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
savannahostrowski enabled auto-merge (squash) December 5, 2025 15:48
savannahostrowski merged commit 4b14529 into python:main Dec 5, 2025
46 checks passed
StanFromIreland pushed a commit to StanFromIreland/cpython that referenced this pull request Dec 6, 2025
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>

hamdanal commented Dec 7, 2025

Copy link
Copy Markdown
Contributor

This PR broke instantiating the formatter outside the parser because _theme is no longer set in __init__ as _set_color is no longer called.

import argparse

formatter = argparse.HelpFormatter(prog="program")
formatter.add_usage(usage=None, actions=[], groups=[])
print(formatter.format_help())

This now raises an AttributeError:

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.

Copy link
Copy Markdown
Member Author

Hey @hamdanal, thanks for raising this! Direct instantiation of HelpFormatter should continue to work. I think the fix is to call self._set_color(False) at the end of __init__ to initialize _theme with a no-color default. The parser can still override it afterward. I've put up #142384 to address this.

hugovk commented Dec 7, 2025

Copy link
Copy Markdown
Member

@hamdanal And thank you for testing the nightly and reporting so quickly :)

tacaswell added a commit to tacaswell/build that referenced this pull request Dec 8, 2025
This is broken with cpython main which removed the color keyword argument
to HelperFormatter in python/cpython#142274
tacaswell added a commit to tacaswell/build that referenced this pull request Dec 8, 2025
This is broken with cpython main which removed the color keyword argument
to HelperFormatter in python/cpython#142274
henryiii pushed a commit to pypa/build that referenced this pull request Dec 8, 2025
This is broken with cpython main which removed the color keyword argument
to HelperFormatter in python/cpython#142274

hroncok commented Dec 18, 2025

Copy link
Copy Markdown
Contributor

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

hroncok commented Dec 18, 2025

Copy link
Copy Markdown
Contributor

Reported as #142928, so it is trackable.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL