Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
Description
Bug report
Bug description:
Given this example script
importargparseclassCsvListAction(argparse.Action):""" argparse Action to convert "a,b,c" into ["a", "b", "c"] """def__call__(self,parser,namespace,values,option_string=None):# Conversion to dict removes duplicates while preserving orderitems=list(dict.fromkeys(values.split(",")).keys())setattr(namespace,self.dest,items)parser=argparse.ArgumentParser(description="Testing")parser.add_argument("directory",type=str,help="path to find files")parser.add_argument("--output",type=str,help="name of output file to produce",)name_args_group=parser.add_mutually_exclusive_group()name_args_group.add_argument("--name-exclude",action=CsvListAction,help="Comma-separated set of name ID(s) to exclude",)name_args_group.add_argument("--name-include",action=CsvListAction,help="Comma-separated set of name ID(s) to include",)parser.add_argument("--path-exclude",action=CsvListAction,default=[],help="Comma-separated set of UNIX glob patterns to exclude",)parser.add_argument("--path-include",action=CsvListAction,default=[],help="Comma-separated set of UNIX glob patterns to include",)parser.parse_args()
Notice the cli args arename-exclude andname-include
Run the following command, which incorrectly puts the arg as--namepython argparse_mini.py /some/path --output here.txt --name something --path-exclude *request.py
If you run it with Python 3.12.2 or below, the resulting log statement is what we expectargparse_mini.py: error: ambiguous option: --name could match --name-exclude, --name-include
However, tested with 3.12.7 and the log statement instead isargparse_mini.py: error: ambiguous option: *request.py could match --name-exclude, --name-include
which is clearly incorrect, as*request.py was the argument to a different CLI option
CPython versions tested on:
3.11, 3.12
Operating systems tested on:
macOS
Linked PRs
Metadata
Metadata
Assignees
Labels
Projects
Status
Doc issues