8000 Add “maybe you meant” in argparse `choices` argument · Issue #99749 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
NIKDISSV-Forever opened this issue Nov 24, 2022 · 3 comments
Closed

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

NIKDISSV-Forever opened this issue Nov 24, 2022 · 3 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@NIKDISSV-Forever
Copy link
NIKDISSV-Forever commented Nov 24, 2022

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

@NIKDISSV-Forever NIKDISSV-Forever added the type-feature A feature request or enhancement label Nov 24, 2022
@sobolevn sobolevn added the stdlib Python modules in the Lib dir label Nov 24, 2022
@sobolevn
Copy link
Member

Do you want to work on this? :)

@NIKDISSV-Forever
Copy link
Author
NIKDISSV-Forever commented Nov 25, 2022

I don't mind working on it, I have an idea of ​​how argparse works, it's just that I'm not a professional in git and have never done pull requests.

While this is a really good idea, I'll start working on it today.

@savannahostrowski
Copy link
Member

Now completed with #124456

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement
Projects
Status: Doc issues
Development

No branches or pull requests

3 participants
0