Skip to content
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

Update optparse to argparse #295

Merged
merged 2 commits into from
Dec 9, 2021
Merged

Update optparse to argparse #295

merged 2 commits into from
Dec 9, 2021

Conversation

andmis
Copy link
Contributor

@andmis andmis commented Dec 7, 2021

optparse is deprecated since Python 3.2: https://docs.python.org/3/library/optparse.html

This PR updates the optparse code to use argparse, as well as to use the variable naming conventions that are typically used with argparse code. See: https://docs.python.org/3/library/argparse.html#upgrading-optparse-code

Also: you had one function called parse_args which (1) built a parser, and (2) invoked the parser to actually read the command line args, and then execute some follow-up logic. I broke this into two functions.

Some context

I have a simple script for automatically-generating fish completions for commands implemented in Python. I was using it to generate nodeenv completions for fish (submitted in this PR). Since most Python commands use argparse, and optparse is deprecated, I went ahead and bumped nodeenv to argparse.

Notes

For long arguments --like-this=some_value, using the equals sign is optional: https://stackoverflow.com/questions/14567289/equals-sign-in-pythons-argument

I understand if you don't want to merge this upstream for whatever reason (inconvenience, not worth it for you, etc.), but I figured I'd submit in case you like the bump to argparse.

Optparse is deprecated since Python 3.2:

    https://docs.python.org/3/library/optparse.html

This PR updates the optparse code to use argparse, as well as
to use the variable naming conventions that are typically used
with argparse code. See:

    https://docs.python.org/3/library/argparse.html#upgrading-optparse-code
@ekalinin ekalinin merged commit e545cc2 into ekalinin:master Dec 9, 2021
@ekalinin
Copy link
Owner

ekalinin commented Dec 9, 2021

Thanks!

@andmis andmis deleted the update-optparse-to-argparse branch December 9, 2021 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants