-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
argparse
Prints options per flag name when only once is necessary
#101599
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
Comments
I agree that such a verbosity clutters the help output so it should be deduplicated into a description column. Also, there is no corresponding example in https://docs.python.org/3/library/argparse.html. I mark it as a feature request, not a bug because such a verbosity explains things in direct, dumb, undesirable but working way. |
@bethard, @bitdancer as prominent contributors into |
Not just multiple choices, it does the same thing for metavar placeholders: import argparse
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
'-m', '--metric',
choices=["accuracy", "precision", "recall"],
help="By which metric trick'd be thee met, Ric?")
parser.add_argument(
'-d', '--debug', metavar='DEBUG_LEVEL',
action='store', type=int,
help="Set the debug level (default: 0)")
parser.parse_args(["-h"]) $ python3 ./ap.py --help
usage: ap.py [-h] [-m {accuracy,precision,recall}] [-d DEBUG_LEVEL]
options:
-h, --help show this help message and exit
-m {accuracy,precision,recall}, --metric {accuracy,precision,recall}
By which metric trick'd be thee met, Ric?
-d DEBUG_LEVEL, --debug DEBUG_LEVEL
Set the debug level (default: 0) Points for consistency, I guess, but " |
If the option with argument has short and long names, output argument only once, after the long name: -o, --option ARG description instead of -o ARG, --option ARG description
And update the docs? For example, at least:
https://docs.python.org/3.13/howto/argparse.html#combining-positional-and-optional-arguments I didn't spot any in the library reference, but it needs checking too: https://docs.python.org/3.13/library/argparse.html#module-argparse cc @Jokimax |
…103372) If the option with argument has short and long names, output argument only once, after the long name: -o, --option ARG description instead of -o ARG, --option ARG description
…103372) If the option with argument has short and long names, output argument only once, after the long name: -o, --option ARG description instead of -o ARG, --option ARG description
…utorial (pythonGH-124025) (cherry picked from commit e5b0185) Co-authored-by: Savannah Ostrowski <savannahostrowski@gmail.com>
…utorial (pythonGH-124025) (cherry picked from commit e5b0185) Co-authored-by: Savannah Ostrowski <savannahostrowski@gmail.com>
Thanks all! |
Uh oh!
There was an error while loading. Please reload this page.
Bug report
When running a command line program with the
--help/-h
flag withargparse
, if another flag has multiple names and choices to pick from, the options are printed multiple times instead of just once. For example, the program below:Will print
Notice that the flag choices are printed out twice, once for each flag name. This is redundant and negatively impacts readability. The program should output:
Your environment
Linked PRs
The text was updated successfully, but these errors were encountered: