Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Python3.15a3 breaks %(default)x in help strings #142980

Copy link
Copy link
@alexprengere

Description

@alexprengere
Issue body actions

Bug report

Bug description:

Since the merge of #141940, the following is broken:

import argparse

parser = argparse.ArgumentParser()
parser.add_argument(
    "--foo",
    type=int,
    default=1234,
    help="0x%(default)x",
)

args = parser.parse_args()

It will trigger:

Traceback (most recent call last):
  File "/Users/aprengere/Dev/cpython/Lib/argparse.py", line 1792, in _check_help
    formatter._expand_help(action)
    ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
  File "/Users/aprengere/Dev/cpython/Lib/argparse.py", line 695, in _expand_help
    return help_string % params
           ~~~~~~~~~~~~^~~~~~~~
TypeError: %x format: an integer is required, not str

The reason is that now the values are "colored" (thus converted to str) before doing the actual interpolation using help_string % values.
If the expected type is not string (integer in this example), then the --help will fail.

I will try to fix this using a different approach for #141940

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.15pre-release feature fixes, bugs and security fixespre-release feature fixes, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    No fields configured for issues without a type.

    Projects

    Status
    Doc issues
    Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.