FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

GH-142950: Process format specifiers before colourization in argparse help by savannahostrowski · Pull Request #142960 · python/cpython · GitHub

/ cpython Public

GH-142950: Process format specifiers before colourization in argparse help - #142960

Merged
savannahostrowski merged 8 commits into
python:mainfrom
savannahostrowski:argparse-format-specifier
Jan 7, 2026
Merged

GH-142950: Process format specifiers before colourization in argparse help#142960
savannahostrowski merged 8 commits into
python:mainfrom
savannahostrowski:argparse-format-specifier

Conversation

savannahostrowski commented Dec 18, 2025
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Member

alexprengere commented Dec 19, 2025
edited
Loading

Copy link
Copy Markdown
Contributor

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.

Comment thread Lib/argparse.py Outdated
Comment thread Lib/argparse.py Outdated

Copy link
Copy Markdown
Member Author

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!

Comment thread Lib/argparse.py
Comment thread Lib/argparse.py
savannahostrowski enabled auto-merge (squash) January 7, 2026 17:13
savannahostrowski merged commit 9a3263f into python:main Jan 7, 2026
46 checks passed
thunder-coding pushed a commit to thunder-coding/cpython that referenced this pull request Feb 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to 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.

5 participants


Back | FazBrowse Home | New Git URL