This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: argparse: show choices once per argument
Type: behavior Stage: patch review
Components: Library (Lib) Versions: Python 3.10
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: mendelmaleh, paul.j3, python-dev, rhettinger, shihai1991
Priority: normal Keywords: patch

Created on 2020-11-04 11:21 by mendelmaleh, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 23143 open python-dev, 2020-11-04 11:49
Messages (2)
msg380509 - (view) Author: Hai Shi (shihai1991) * (Python triager) Date: 2020-11-07 14:36
I like your improvement.
But I suggest you should copy your first comment from your PR to here.(It's easy for discuss in here;)
msg380771 - (view) Author: (mendelmaleh) * Date: 2020-11-11 16:49
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
```py
import argparse

ap = argparse.ArgumentParser(allow_abbrev=False)
ap.add_argument('-c', '--choices', choices=['a', 'b', 'c'])
ap.parse_args()
```

### previous output
```
usage: main.py [-h] [-c {a,b,c}]

optional arguments:
  -h, --help            show this help message and exit
  -c {a,b,c}, --choices {a,b,c}
```

### new output
```
usage: main.py [-h] [-c {a,b,c}]

optional arguments:
  -h, --help            show this help message and exit
  -c, --choices {a,b,c}
```
History
Date User Action Args
2022-04-11 14:59:37adminsetgithub: 86424
2020-11-11 16:50:00mendelmalehsetmessages: + msg380771
2020-11-07 14:36:44shihai1991setnosy: + shihai1991, rhettinger, paul.j3
messages: + msg380509
2020-11-04 11:49:24python-devsetkeywords: + patch
nosy: + python-dev

pull_requests: + pull_request22056
stage: patch review
2020-11-04 11:21:13mendelmalehcreate