Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Argparse logs incorrect ambiguous option #125254

Closed
Assignees
serhiy-storchaka
Labels
3.12only security fixes3.13bugs and security fixes3.14bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error
@clavedeluna

Description

@clavedeluna

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--name
python 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 expect
argparse_mini.py: error: ambiguous option: --name could match --name-exclude, --name-include

However, tested with 3.12.7 and the log statement instead is
argparse_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

Labels

3.12only security fixes3.13bugs and security fixes3.14bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

Projects

Status

Doc issues

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp