Skip to content

Conversation

@cdce8p
Copy link
Collaborator

@cdce8pcdce8p commented May 3, 2025

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
@cdce8pcdce8pforce-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.

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

This comment has been minimized.

Copy link
Collaborator

@sterliakovsterliakov left a comment

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
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.

Copy link
Collaborator

@hamdanalhamdanal left a comment

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.

@cdce8pcdce8pforce-pushed the argparse-color-output branch from 954cada to 94052a7CompareMay 4, 2025 14:06
@cdce8pcdce8p requested a review from hamdanalMay 4, 2025 14:07
@github-actions
Copy link
Contributor

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

@JelleZijlstraJelleZijlstra merged commit e7405c9 into python:masterMay 4, 2025
18 checks passed
@cdce8pcdce8p 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