Skip to content

argparse allow_abbrev option also controls short flag combinations #76208

Closed

Description

@joernhees
mannequin
BPO 32027
Nosy @berkerpeksag, @joernhees
PRs
  • bpo-32027: Doc: add note that argparse allow_abbrev=False deactivates flag combinations #4396
  • Superseder
  • bpo-26967: argparse: allow_abbrev=False stops -vv from working
  • 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 = <Date 2017-11-16.08:01:13.956>
    created_at = <Date 2017-11-14.17:29:42.336>
    labels = ['3.7', 'type-bug', 'library', 'docs']
    title = 'argparse allow_abbrev option also controls short flag combinations'
    updated_at = <Date 2018-09-11.01:47:50.345>
    user = 'https://github.com/joernhees'

    bugs.python.org fields:

    activity = <Date 2018-09-11.01:47:50.345>
    actor = 'paul.j3'
    assignee = 'docs@python'
    closed = True
    closed_date = <Date 2017-11-16.08:01:13.956>
    closer = 'berker.peksag'
    components = ['Documentation', 'Library (Lib)']
    creation = <Date 2017-11-14.17:29:42.336>
    creator = 'joern'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 32027
    keywords = ['patch']
    message_count = 3.0
    messages = ['306229', '306343', '324976']
    nosy_count = 4.0
    nosy_names = ['docs@python', 'berker.peksag', 'joern', 'paul.j3']
    pr_nums = ['4396']
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '26967'
    type = 'behavior'
    url = 'https://bugs.python.org/issue32027'
    versions = ['Python 3.6', 'Python 3.7']

    Activity

    1. joernhees commented on Nov 14, 2017

      joernheesmannequin
      MannequinAuthor

      The allow_abbrev option (default True) currently is documented like this (https://docs.python.org/3/library/argparse.html#allow-abbrev):

      Normally, when you pass an argument list to the parse_args() method of an ArgumentParser, it recognizes abbreviations of long options.

      However, it also controls combinations of short options and especially the combination of flags (store_const) like -a -b as -ab.

      Example snippet for testing:

      import argparse
      import sys
      
      parser = argparse.ArgumentParser(
          allow_abbrev=False
      )
      parser.add_argument('-a', action='store_true')
      parser.add_argument('-b', action='store_true')
      parser.add_argument('x', nargs='*')
      parser.parse_args('-a -b foo bar'.split())
      parser.parse_args('-ab foo bar'.split())

      As you can see the 2nd parse will fail if allow_abbrev=False.

      This issue is either a doc issue only or an unintended combination of long option shortening and (the way more common) flag combinations. When i deactivated this in my code, i wanted to disable the (nice to have) long option shortening, but i unintentionally also deactivated (MUST have) short flag combinations.

    2. added
      3.8 (EOL)
      3.7 (EOL)
      on Nov 14, 2017
    3. added
      docs
      stdlib
      on Nov 14, 2017
    4. berkerpeksag commented on Nov 16, 2017

      @berkerpeksag
      Member

      Thank you for the report and for the PR. I think this is a duplicate of bpo-26967.

      This issue is either a doc issue only or an unintended combination of
      long option shortening and (the way more common) flag combinations.

      This is indeed a bug so it would be better to fix it.

    5. added
      type-bug
      on Nov 16, 2017
    6. paulj3 commented on Sep 11, 2018

      paulj3mannequin
      Mannequin

      The PR 4396 should be closed.

    7. transferred this issue fromon Apr 10, 2022
    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.7 (EOL)docsstdlibtype-bug

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions