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

argparse: ambiguous option reported with primary parser #109990

Copy link
Copy link
@getsimonz

Description

@getsimonz
Issue body actions

Bug report

Bug description:

When we have sub_parser argument which is substring of main parser, getting error as ambiguous option

python sample.py show -foo "data"
usage: PROG [-h] [-foobar FOOBAR] [-foobar1 FOOBAR1] {show} ...
PROG: error: ambiguous option: -foo could match -foobar, -foobar1

Observing with python 3.11.3. Earlier it works fine with python 3.5

# Add a code block here, if required
parser = argparse.ArgumentParser(prog='PROG', allow_abbrev=False)
parser.add_argument('-foobar', action='store')
parser.add_argument('-foobar1', action='store')
sub_parser = parser.add_subparsers(dest='command')
# Show
sub_parser_show = sub_parser.add_parser('show', help='Print Client ID for a specific environment',
											description= 'Print Client ID for a specific environment')
sub_parser_show.add_argument('-foo', dest = 'env_name', action='store', 
										help='Environment name Eg: "development"')

args = parser.parse_args()
print (args)

CPython versions tested on:

3.11

Operating systems tested on:

Linux

Linked PRs

Reactions are currently unavailable

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
    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.