Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

argparse metavar parentheses dropped on usage line #101979

Closed
Labels
stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error
@tonyle72

Description

@tonyle72

Parentheses in argparsemetavars are dropped on theusage line but appear as expected in the argument list. In particular, the very first and very last parentheses disappear. It looks from other issues (e.g.#56083) that braces, brackets and parentheses inmetavars are problematic, so this may be part of a wider and more difficult set of puzzlers to fix.

Illustrative code:

#!/usr/bin/python3"""Demonstrate parenthesis drops in argparse metavar."""import argparse# The very first and last parentheses disappear in the usage line, but are# present in the argument list.parser = argparse.ArgumentParser(    description='Demonstrate parenthesis drops in argument meta-descriptions')parser.add_argument(    'positional',    help='positional argument',    metavar='(example) positional')parser.add_argument(    '-p',    '--optional',    help='optional argument',    type=int,    choices=[1, 2],    metavar='{1 (option A), 2 (option B)}',    default=1)arguments = parser.parse_args()print(arguments)

When this is run with-h, the help text is rendered as shown below. Note the parentheses are missing beforeoption A and afterexample:

usage: parens.py [-h] [-p {1 option A), 2 (option B)}] (example positionalDemonstrate parenthesis drops in argument meta-descriptionspositional arguments:  (example) positional  positional argumentoptional arguments:  -h, --help            show this help message and exit  -p {1 (option A), 2 (option B)}, --optional {1 (option A), 2 (option B)}                        optional argument

I've tried this on Python 3.8.10 and Python 3.10.6.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    Doc issues

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp