GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — argparse metavar parentheses dropped on usage line · Issue #101979 · python/cpython

argparse metavar parentheses dropped on usage line #101979

New issue
Copy link
New issue
Copy link
Closed
Closed
argparse metavar parentheses dropped on usage line#101979
Copy link
Labels
stdlibStandard 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

Description

@tonyle72
tonyle72
opened on Feb 17, 2023
Issue body actions

Parentheses in argparse metavars are dropped on the usage 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 in metavars 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 before option A and after example:

usage: parens.py [-h] [-p {1 option A), 2 (option B)}] (example positional

Demonstrate parenthesis drops in argument meta-descriptions

positional arguments:
  (example) positional  positional argument

optional 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

  • gh-101979: fix a bug that parentheses in metavar argument of add_argument() were dropped #102318
  • [3.11] gh-101979: argparse: fix a bug where parentheses in metavar argument of add_argument() were dropped (GH-102318) #102438
  • [3.10] gh-101979: argparse: fix a bug where parentheses in metavar argument of add_argument() were dropped (GH-102318) #102439

Activity

  1. tonyle72
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Feb 17, 2023
  2. arhadthedev
    added
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    on Feb 17, 2023
  3. arhadthedev
    added this to Argparse issueson Feb 17, 2023
  4. erlend-aasland
    moved this to Bugs in Argparse issueson Feb 21, 2023
  5. JelleZijlstra
    added a commit that references this issue on Mar 5, 2023

    gh-101979: argparse: fix a bug where parentheses in metavar argument …

    9a478be
  6. miss-islington
    added 4 commits that reference this issue on Mar 5, 2023

    pythongh-101979: argparse: fix a bug where parentheses in metavar arg…

    97fde49

    pythongh-101979: argparse: fix a bug where parentheses in metavar arg…

    20dfd9a

    gh-101979: argparse: fix a bug where parentheses in metavar argument …

    2a062f2

    gh-101979: argparse: fix a bug where parentheses in metavar argument …

    e748f9e
  7. corona10
    closed this as completedon Mar 6, 2023
  8. github-project-automation
    moved this from Bugs to Doc issues in Argparse issueson Mar 6, 2023
  9. hugovk
    added a commit that references this issue on Mar 6, 2023

    pythongh-101979: argparse: fix a bug where parentheses in metavar arg…

    0e240a6
  10. carljm
    added 2 commits that reference this issue on Mar 6, 2023

    Merge branch 'main' into nodeaddict

    33dda2a

    Merge branch 'main' into inlinecomp2

    ecb313c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard 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

    Projects

    • Argparse issues
      Status
      Doc issues
      Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.