[issue42258] argparse: show choices once per argument

mendelmaleh report at bugs.python.org
Wed Nov 11 11:50:00 EST 2020


mendelmaleh <mendelmaleh at gmail.com> added the comment:

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}
```

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42258>
_______________________________________


More information about the Python-bugs-list mailing list