Skip to content

Conversation

@alexprengere
Copy link
Contributor

@alexprengere alexprengere commented Nov 25, 2025

@mpkocher
Copy link
Contributor

Consider adding a test or extending an existing test.

@alexprengere
Copy link
Contributor Author

Of course 😉 (this is a draft PR).
I will extend the color test in test_argparse, I wanted to be sure whether to color all interpolated values or just default.
Also I am unsure whether to re-use theme.default_value or introduce new values in _colorize.py like #141680 did.
I will clean this up tomorrow and then mark it as ready for review.

@alexprengere
Copy link
Contributor Author

I updated the code and tests 😉

I had to change a bit the logic introduced in #141680 as introducing a new color for interpolated values, that would be different from the default_value color, is a bit complex to handle.

For ArgumentDefaultsHelpFormatter, as _get_help_string returns the %(default)s already "colored", updating _expand_help to "color" interpolated values would essentially color the default values twice, and no longer respect the default_value color.
So I removed the coloring of %(default)s in _get_help_string, and now it happens in _expand_help, as the default value will be colored, along all interpolated values, using a sinple interpolated_value color.

I hope this is clear, I can amend this if needed.

@alexprengere
Copy link
Contributor Author

alexprengere commented Nov 28, 2025

For the record the PR could be slightly improved with the formatting of choices, by coloring each individual values before joining them with ', '.
I tried it but encountered bug in an unrelated part (filed in #142035):

image

The issue is that the use of textwrap.wrap happens after the ANSI codes have been inserted, causing the wrapping to be broken in some cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants