Skip to content

Enable colored output for argparse help in Python 3.14 - #19021

Merged
JelleZijlstra merged 3 commits into
python:masterfrom
cdce8p:argparse-color-output
May 4, 2025
Merged

Enable colored output for argparse help in Python 3.14#19021
JelleZijlstra merged 3 commits into
python:masterfrom
cdce8p:argparse-color-output

Conversation

@cdce8p

@cdce8pcdce8p commented May 3, 2025

Copy link
Copy Markdown
Collaborator

Support for colored output was just merged in cpython. Maybe a bit early to add it here already but it doesn't hurt either.

CurrentWith color
Without colorWith color

The color output can be disable using various environment variables.
https://docs.python.org/3.14/using/cmdline.html#using-on-controlling-color

@cdce8pcdce8p changed the title Enable colored output for argparse in 3.14Enable colored output for argparse in Python 3.14May 3, 2025
@cdce8p
cdce8pforce-pushed the argparse-color-output branch from 102b99e to 3368f64CompareMay 3, 2025 09:58
@cdce8pcdce8p changed the title Enable colored output for argparse in Python 3.14Enable colored output for argparse help in Python 3.14May 3, 2025
@github-actions

This comment has been minimized.

@cdce8p
cdce8pforce-pushed the argparse-color-output branch from 3368f64 to 634c4d4CompareMay 3, 2025 11:28
@github-actions

This comment has been minimized.

@sterliakovsterliakov left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This certainly looks nice! Are we sure these changes will be present in final 3.14 release? As usual, there's some chance that unreleased functionality may be removed/renamed/significantly altered.

@cdce8p

Copy link
Copy Markdown
CollaboratorAuthor

Are we sure these changes will be present in final 3.14 release? As usual, there's some chance that unreleased functionality may be removed/renamed/significantly altered.

There is always the possibility that a new feature gets reverted before the final release, though I don't suspect it happening here. Nevertheless if that should happen, a lot of test cases would fail with 3.14 at which point we could just revert this one.

@hamdanalhamdanal left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this, I think it is a huge readability upgrade to have colors in the help text of a CLI (the reason I proposed #14455 earlier). I have two suggestions for this change:

  1. Please also change dmypy, stubgen and stubtest parsers
  2. Instead of branching on the python version and passing a keywords dictionary, set the color attribute on the parser instance after initialization, as it is recommended in the argparse documentation.

@cdce8p
cdce8pforce-pushed the argparse-color-output branch from 954cada to 94052a7CompareMay 4, 2025 14:06
@cdce8p
cdce8p requested a review from hamdanalMay 4, 2025 14:07
@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@JelleZijlstra
JelleZijlstra merged commit e7405c9 into python:masterMay 4, 2025
@cdce8p
cdce8p deleted the argparse-color-output branch May 4, 2025 15:42
@cdce8pcdce8p mentioned this pull request May 29, 2025
ilevkivskyi pushed a commit that referenced this pull request Aug 25, 2025
…" (#19721)
Reverts #19021
After the PR was merged, `color` was changed to `true` for Python 3.14.
Setting it manually is no longer necessary.
python/cpython#136809https://docs.python.org/3.14/library/argparse.html#color
Sign up for freeto 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

@cdce8p@sterliakov@hamdanal@JelleZijlstra