-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
bpo-42258: argparse: show choices once per argument #23143
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
Conversation
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA). Recognized GitHub usernameWe couldn't find a bugs.python.org (b.p.o) account corresponding to the following GitHub usernames: This might be simply due to a missing "GitHub Name" entry in one's b.p.o account settings. This is necessary for legal reasons before we can look at this contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. You can check yourself to see if the CLA has been received. Thanks again for the contribution, we look forward to reviewing it! |
This PR is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works on test case plus
./python -m test -v test_argparse
Ran 1656 tests in 3.191s
OK
== Tests result: SUCCESS ==
1 test OK.
Total duration: 3.5 sec
Tests result: SUCCESS
cpython on bpo-42258 [$?] via 🐍 v3.11.0a5+ took 4s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion, but I don't like the way this changes the help:
usage: test.py [-h] [-x xyz]
options:
-h, --help show this help message and exit
-x xyz, --x xyz
to:
usage: test.py [-h] [-x xyz]
optional arguments:
-h, --help show this help message and exit
-x, --x xyz
Since that makes it look like there isn't an argument when you use -x
.
parser = argparse.ArgumentParser()
parser.add_argument("-x", "--x", metavar="xyz")
parser.parse_args()
When using more than one flag for an argument, it is redundant to have the choices more than once, since they are the same argument and have the same choices.
Showing it once means cleaner output, and often means that the other option lines are shorter, like in the test case.
sample code
previous output
new output
https://bugs.python.org/issue42258