Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
Description
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:
importargparseif__name__=="__main__":parser=ArgumentParser()parser.add_argument('-m','--metric',choices=["accuracy","precision","recall"])parser.parse_args(["-h"])
Will print
usage: argparse_test.py [-h] [-m {accuracy,precision,recall}]options: -h, --help show thishelp message andexit -m {accuracy,precision,recall}, --metric {accuracy,precision,recall}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:
usage: argparse_test.py [-h] [-m {accuracy,precision,recall}]options: -h, --help show thishelp message andexit -m, --metric {accuracy,precision,recall}Your environment
- CPython versions tested on: 3.10.6
- Operating system and architecture: Windows 11 with WSL 2
Linked PRs
- gh-101599: changed argparse -h/-help flag for the sake of readability #103372
- GH-101599: Update docs to remove redundant option in argparse tutorial #124025
- [3.12] GH-101599: Update docs to remove redundant option in argparse tutorial (GH-124025) #124036
- [3.13] GH-101599: Update docs to remove redundant option in argparse tutorial (GH-124025) #124037
Metadata
Metadata
Assignees
Labels
Projects
Status
Doc issues