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 usage should preserve () in metavars such as range(20) · Issue #62549 · python/cpython

argparse usage should preserve () in metavars such as range(20) #62549

New issue
Copy link
New issue
Copy link
Closed
Closed
argparse usage should preserve () in metavars such as range(20)#62549
Copy link
Labels
3.10 (EOL)end of lifeend of life3.11only security fixesonly security fixes3.9 (EOL)end of lifeend of lifestdlibStandard 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

paulj3
mannequin
opened on Jul 3, 2013
Issue body actions
BPO 18349
Nosy @iritkatriel
Files
  • metaparen.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2013-07-03.06:16:51.100>
    labels = ['type-bug', 'library', '3.9', '3.10', '3.11']
    title = 'argparse usage should preserve () in metavars such as range(20)'
    updated_at = <Date 2021-12-10.15:48:45.716>
    user = 'https://bugs.python.org/paulj3'

    bugs.python.org fields:

    activity = <Date 2021-12-10.15:48:45.716>
    actor = 'iritkatriel'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2013-07-03.06:16:51.100>
    creator = 'paul.j3'
    dependencies = []
    files = ['30754']
    hgrepos = []
    issue_num = 18349
    keywords = ['patch']
    message_count = 5.0
    messages = ['192222', '192717', '193077', '193188', '408214']
    nosy_count = 2.0
    nosy_names = ['paul.j3', 'iritkatriel']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = None
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue18349'
    versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

    Activity

    1. paulj3 commented on Jul 3, 2013

      @paulj3
      paulj3mannequin
      on Jul 3, 2013
      MannequinAuthor
      More actions

      As discussed in bpo-16468, a metavar may be used to provide an alternative representation of a choices option. However if a metvar like 'range(20)' is used, usage formatter strips off the '()'.

          >>> parser.add_argument('foo', type=int, 
              choices=range(20), metavar='range(0,20)')
          >>> parser.format_usage()
          # expect: 'usage: PROG [-h] range(0,20)\n'
          # actual: 'usage: PROG [-h] range0,20\n'

      This is done by a line in the help formater that removes excess mutually exclusive group notation:

      HelpFormatter._format_actions_usage
         ...
         text = _re.sub(r'\(([^|]*)\)', r'\1', text)
      

      A solution is to change this line to distinguish between a case like ' (...)' and 'range(...)'

          text = _re.sub(r'( )\(([^|]*)\)', r'\1\2', text)
    2. paulj3
      added
      stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
      type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
      on Jul 3, 2013
    3. paulj3 commented on Jul 9, 2013

      @paulj3
      paulj3mannequin
      on Jul 9, 2013
      MannequinAuthor
      More actions

      I just posted a patch to http://bugs.python.org/issue16468 that uses (and tests) this fix.

    4. paulj3 commented on Jul 15, 2013

      @paulj3
      paulj3mannequin
      on Jul 15, 2013
      MannequinAuthor
      More actions

      This issue should also preserve a metavar like: '(one)two', i.e. '(' at the start.

      In http://bugs.python.org/issue10984 these _re replacements are applied to individual action strings as well as the whole usage line. So if () are to be removed from '[-h] (-y)', they should also be removed from '(-y)'.

    5. paulj3 commented on Jul 16, 2013

      @paulj3
      paulj3mannequin
      on Jul 16, 2013
      MannequinAuthor
      More actions

      I just submitted at patch to http://bugs.python.org/issue11874 that takes care of this issue as well.

      I rewrote _format_actions_usage() so it formats the parts directly, so there is no need cleanup or parse the full text string.

    6. iritkatriel commented on Dec 10, 2021

      @iritkatriel
      iritkatriel
      on Dec 10, 2021
      Member
      More actions

      Reproduced on 3.11:

      >>> import argparse
      >>> parser = argparse.ArgumentParser()
      >>> parser.add_argument('foo', type=int, choices=range(20), metavar='range(0,20)')
      _StoreAction(option_strings=[], dest='foo', nargs=None, const=None, default=None, type=<class 'int'>, choices=range(0, 20), help=None, metavar='range(0,20)')
      >>> parser.format_usage()
      'usage: [-h] range0,20\n'
    7. iritkatriel
      added
      3.9 (EOL)end of lifeend of life
      3.10 (EOL)end of lifeend of life
      3.11only security fixesonly security fixes
      on Dec 10, 2021
    8. ezio-melotti
      transferred this issue fromon Apr 10, 2022
    9. erlend-aasland
      added this to Argparse issueson May 19, 2022
    10. erlend-aasland
      moved this to Bugs in Argparse issueson May 19, 2022
    11. hamdanal
      added a commit that references this issue on May 28, 2023

      Simplify argparse usage formatting

      This issue will close once commit 4336ac7 is merged into the 'main' branch.
      4336ac7
    12. encukou
      added a commit that references this issue on May 7, 2024

      gh-62090: Simplify argparse usage formatting (GH-105039)

      de1428f
    13. encukou commented on May 7, 2024

      @encukou
      encukou
      on May 7, 2024
      Member
      More actions

      This was fixed in #102318.

    14. encukou
      closed this as completedon May 7, 2024
    15. github-project-automation
      moved this from Bugs to Doc issues in Argparse issueson May 7, 2024
    16. SonicField
      added a commit that references this issue on May 8, 2024

      pythongh-62090: Simplify argparse usage formatting (pythonGH-105039)

      8047c0b
    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

      3.10 (EOL)end of lifeend of life3.11only security fixesonly security fixes3.9 (EOL)end of lifeend of lifestdlibStandard 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.