Update optparse to argparse#295
Merged
ekalinin merged 2 commits intoekalinin:masterfrom Dec 9, 2021
andmis:update-optparse-to-argparse
Merged
Update optparse to argparse#295ekalinin merged 2 commits intoekalinin:masterfrom andmis:update-optparse-to-argparse
ekalinin merged 2 commits intoekalinin:masterfrom
andmis:update-optparse-to-argparse
Conversation
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
Owner
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
optparseis deprecated since Python 3.2: https://docs.python.org/3/library/optparse.htmlThis PR updates the
optparsecode to useargparse, as well as to use the variable naming conventions that are typically used withargparsecode. See: https://docs.python.org/3/library/argparse.html#upgrading-optparse-codeAlso: you had one function called
parse_argswhich (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
nodeenvcompletions for fish (submitted in this PR). Since most Python commands useargparse, andoptparseis deprecated, I went ahead and bumped nodeenv toargparse.Notes
For long arguments
--like-this=some_value, using the equals sign is optional: https://stackoverflow.com/questions/14567289/equals-sign-in-pythons-argumentI 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.