Skip to content

Cannot use format specifiers in argparse help #142950

Closed

Description

@savannahostrowski

#141940 caused a regression where users cannot use format specifiers.


See this as an example

my_parser.add_argument(
        "--foo",
        type=int,
        default=1234,
        help=f"""0x%(default)x""",
    )

The above works in 3.14.2, but not in 3.15 alpha3. I apologize if my code is doing something incorrect.

The error I get is

Traceback (most recent call last):
  File "[...]/3.15.0a3/lib/python3.15/argparse.py", line 1793, in _check_help
    formatter._expand_help(action)
    ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
  File "[...]/3.15.0a3/lib/python3.15/argparse.py", line 696, in _expand_help
    return help_string % params
           ~~~~~~~~~~~~^~~~~~~~
TypeError: %x format: an integer is required, not str

Originally posted by @oyvindronningstad in #141940 (comment)

Linked PRs

Activity

  1. gitlostmyaccounttt commented on Dec 18, 2025

    @gitlostmyaccounttt
  2. added
    type-bugAn unexpected behavior, bug, or error
    stdlibStandard Library Python modules in the Lib/ directory
    3.15bugs and security fixes
    on Dec 18, 2025
  3. added a commit that references this issue on Dec 20, 2025
  4. added a commit that references this issue on Jan 7, 2026
  5. added a commit that references this issue on Feb 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

3.15bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions