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

Add “maybe you meant” in argparsechoices argument #99749

Closed
Assignees
savannahostrowski
Labels
stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement
@NIKDISSV-Forever

Description

@NIKDISSV-Forever

argparse guesses

Print the possible (nearest) value of the argument. If options are specified with thechoices argument.

Pitch

argparse are end user oriented.
Such a message will make the program interface more user-friendly.

defmain():arg_parser=argparse.ArgumentParser()arg_parser.add_argument('family',type=str.casefold,help='Font family',choices=get_all_family_names(FAMILY_FILES))args=arg_parser.parse_args(['S200Flora'])

Now outputs this:

error: argument family: invalid choice: 's200flora' (choose from 'a431', ..., 's200flor', ... 'wingdings 3')

I suggest making the output look like this:

error: argument family: invalid choice: 's200flora',maybe you meant 's200flor'? (choose from 'a431', ..., 's200flor', ... 'wingdings 3')


It doesn't have to look exactly like this. I'm not talking about the implementation, perhaps the assumptions should always be (if there are matches) in the presence of thechoices argument, perhaps only in some certain conditions.
These questions are decided by those who will implement it, as they see fit.

Previous discussion

Add “maybe you meant” in argparsechoices argumenton discuss.python.org

Linked PRs

Metadata

Metadata

Labels

stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

Projects

Status

Doc issues

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp