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

Add “maybe you meant” in argparse choices argument #99749

Copy link
Copy link
@NIKDISSV-Forever

Description

@NIKDISSV-Forever
Issue body actions

argparse guesses

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

Pitch

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

def main():
    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 the choices 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 argparse choices argument on discuss.python.org

Linked PRs

Reactions are currently unavailable

Metadata

Metadata

Labels

stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement
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.