Skip to content

Conversation

@hugovk
Copy link
Member

@hugovk hugovk commented Nov 17, 2025

@hugovk hugovk added the stdlib Standard Library Python modules in the Lib/ directory label Nov 17, 2025
@hugovk hugovk changed the title gh-130645: Add colour to defaults in argparse help gh-141679: Add colour to defaults in argparse help Nov 17, 2025
Copy link
Member

@savannahostrowski savannahostrowski left a comment

Choose a reason for hiding this comment

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

One comment about the two-color choice - I wonder if it might be a bit busy with the frequent color switching.

But overall, this looks really good and aligns with modern CLIs, IMO. I pretty extensively tested this and I couldn't find any issues. I also think it's fine to not apply color in help text when users might have literally written (default: ).

@mpkocher
Copy link
Contributor

One comment about the two-color choice - I wonder if it might be a bit busy with the frequent color switching.

It would be useful to push these changes and then try to get as much feedback as possible before the 3.15 release. I agree that it does look a little too busy.

I believe it would be good idea to make the ThemeSection (and colorize) public and more clearly define the backwards compatibility rules. This would allow people to set the theme (for argparse) when initializing the ArgumentParser instance.

Not sure if there was a follow up issue created from the "Open Issues" section of #133346 (specifically, clarifying how schema changes of a ThemeSection should be handled).

It should be possible for the user to keep using a theme from 3.14 in future versions of Python without changes. The new color definitions would be automatically taken from the default theme.

In [7]: from _colorize import get_theme

In [8]: t = get_theme().argparse

In [9]: t.action
Out[9]: '\x1b[1;32m'

In [10]: t.default
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[10], line 1
----> 1 t.default

AttributeError: 'Argparse' object has no attribute 'default'

In [11]: t.default_value
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[11], line 1
----> 1 t.default_value

AttributeError: 'Argparse' object has no attribute 'default_value'

@hugovk
Copy link
Member Author

hugovk commented Nov 22, 2025

I believe it would be good idea to make the ThemeSection (and colorize) public and more clearly define the backwards compatibility rules. This would allow people to set the theme (for argparse) when initializing the ArgumentParser instance.

Not sure if there was a follow up issue created from the "Open Issues" section of #133346 (specifically, clarifying how schema changes of a ThemeSection should be handled).

When time allows, I think @ambv is planning on a PEP for adding a colorize module for 3.15, and this would be great input for that discussion.

@savannahostrowski savannahostrowski enabled auto-merge (squash) November 23, 2025 00:01
@savannahostrowski savannahostrowski merged commit e73fbba into python:main Nov 23, 2025
54 checks passed
@hugovk hugovk deleted the 3.15-argparse-default-colour branch November 23, 2025 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stdlib Standard Library Python modules in the Lib/ directory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants