You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 requiredparser=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')
# Showsub_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)
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
CPython versions tested on:
3.11
Operating systems tested on:
Linux
Linked PRs