GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GH-139862: Remove `color` from HelpFormatter by savannahostrowski · Pull Request #142274 · python/cpython

Conversation

@savannahostrowski

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

Uh oh!

There was an error while loading. Please reload this page.

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.

  • Issue: Investigate argparse formatter handling of color #139862

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@savannahostrowski
Remove color from HelpFormatter
bf64653
@savannahostrowski
savannahostrowski requested a review from hugovk December 4, 2025 22:48
@bedevere-app bedevere-app Bot mentioned this pull request Dec 4, 2025
Investigate argparse formatter handling of color #139862
Closed
@bedevere-app bedevere-app Bot added the awaiting core review label Dec 4, 2025
@blurb-it
📜🤖 Added by blurb_it.
1235580
hugovk
hugovk approved these changes Dec 5, 2025
View reviewed changes
Comment thread Misc/NEWS.d/next/Library/2025-12-04-23-24-24.gh-issue-139862.NBfsD4.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Dec 5, 2025
@hugovk
Merge branch 'main' into remove-formatter-color
2977cd7
@hugovk

hugovk commented Dec 5, 2025

Copy link
Copy Markdown
Member

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

savannahostrowski and others added 2 commits December 5, 2025 07:48
@savannahostrowski @hugovk
Update Misc/NEWS.d/next/Library/2025-12-04-23-24-24.gh-issue-139862.N…
e99409e
…BfsD4.rst

Co-authored-by: Hugo van Kemenade <[email protected]>
@savannahostrowski
Merge branch 'main' into remove-formatter-color
4036f63
@savannahostrowski
savannahostrowski enabled auto-merge (squash) December 5, 2025 15:48
@savannahostrowski
savannahostrowski merged commit 4b14529 into python:main Dec 5, 2025
46 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting merge label Dec 5, 2025
StanFromIreland pushed a commit to StanFromIreland/cpython that referenced this pull request Dec 6, 2025
@savannahostrowski @hugovk @StanFromIreland
pythonGH-139862: Remove color from HelpFormatter (python#142274)
f42990f
Co-authored-by: Hugo van Kemenade <[email protected]>
@hamdanal

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@savannahostrowski savannahostrowski mentioned this pull request Dec 7, 2025
GH-139862: Fix direct instantiation of HelpFormatter #142384
Merged
@savannahostrowski

savannahostrowski commented Dec 7, 2025

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.

hamdanal reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@hugovk

hugovk commented Dec 7, 2025

Copy link
Copy Markdown
Member

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

hamdanal reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

tacaswell added a commit to tacaswell/build that referenced this pull request Dec 8, 2025
@tacaswell
MNT: remove workaround for 3.14b1
f26a554
This is broken with cpython main which removed the color keyword argument
to HelperFormatter in python/cpython#142274
@tacaswell tacaswell mentioned this pull request Dec 8, 2025
MNT: remove workaround for 3.14b1 pypa/build#960
Merged
tacaswell added a commit to tacaswell/build that referenced this pull request Dec 8, 2025
@tacaswell
MNT: remove workaround for 3.14b1
792d9ec
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
@tacaswell
MNT: remove workaround for 3.14b1 (#960)
393b775
This is broken with cpython main which removed the color keyword argument
to HelperFormatter in python/cpython#142274
@hroncok

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

savannahostrowski reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@hroncok hroncok mentioned this pull request Dec 18, 2025
argparse.HelpFormatter color argument removed in 3.15.0a3 without deprecation #142928
Closed
@hroncok

hroncok commented Dec 18, 2025

Copy link
Copy Markdown
Contributor

Reported as #142928, so it is trackable.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@savannahostrowski savannahostrowski mentioned this pull request Dec 18, 2025
GH-142928: Add deprecation warning for removal of color on HelpFormatter #142946
Closed
This was referenced Oct 17, 2026
CLI crashes on Python 3.15: HelpFormatter.__init__() rejects color tony/agentgrep#168
Closed
py(3.15): Fix the CLI crash, default to Python 3.15 tony/agentgrep#169
Merged
tony added a commit to tony/agentgrep that referenced this pull request Oct 24, 2026
@tony
py(3.15): Fix the CLI crash, default to Python 3.15 (#169)
4e53843
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@hugovk hugovk hugovk approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@savannahostrowski @hugovk @hamdanal @hroncok
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.