cpython
cpython copied to clipboard
GH-142950: Process format specifiers before colourization in argparse help
- Issue: gh-142950
Thanks for working on this and fixing the bug I introduced 😭 (I was planning to fix it today but saw your PR).
One minor nit: I tested it locally and this will raise when %% is encountered in the help text:
# parser.add_argument("--str", default="test", help="100%%")
#
Traceback (most recent call last):
File "/Users/aprengere/Dev/cpython/Lib/argparse.py", line 1810, in _check_help
formatter._expand_help(action)
~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
File "/Users/aprengere/Dev/cpython/Lib/argparse.py", line 712, in _expand_help
raise ValueError(f"invalid format specifier in: {help_string!r}")
ValueError: invalid format specifier in: '100%%'
This is due to the final check:
if '%' in result:
raise ValueError(f"invalid format specifier in: {help_string!r}")
Removing this check it makes test_invalid_help fail though.
Hey folks - thanks for the thoughtful and thorough feedback on this PR! Apologies for the delay in addressing it - I was out on vacation over the holidays!