bpo-42258: argparse: show choices once per argument by mendelmaleh · Pull Request #23143 · python/cpython (original) (raw)

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

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}

https://bugs.python.org/issue42258