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 choices formatter
Type: behavior Stage:
Components: Library (Lib) Versions:
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Leonid Ilyevsky, paul.j3, rhettinger
Priority: normal Keywords:

Created on 2020-04-28 12:34 by Leonid Ilyevsky, last changed 2022-04-11 14:59 by admin.

Messages (3)
msg367524 - (view) Author: Leonid Ilyevsky (Leonid Ilyevsky) Date: 2020-04-28 12:34
In my script I have a positional argument with list of choices, and that list is pretty long. The help formatter shows it as one long line,  list in curly brackets, comma-separated. This is very difficult to look at and find the choice I need.
It would be nice to have an option to print the choices list one per line.
msg367537 - (view) Author: paul j3 (paul.j3) * (Python triager) Date: 2020-04-28 15:50
The display of the choices has been discussed in previous issues.  When the choices is long there isn't a clean way of handling the display.

I'd suggest using a 'metavar' to show a short value, and then enumerate the choices in the help text.  Use the 'Raw' help formatter to handle newlines as desired.

Choices get displayed in 3 places - the usage, the help, and error messages.  Metavar replaces 2 of those.

An alternative to choices is a custom 'type' function.  An example would be all integers between 0 and 100.  Choices would work, but make a poor display regardless of formatting.
msg368215 - (view) Author: paul j3 (paul.j3) * (Python triager) Date: 2020-05-06 00:06
Related topic re. long usage with choices : https://bugs.python.org/issue16418
History
Date User Action Args
2022-04-11 14:59:30adminsetgithub: 84600
2020-05-06 00:06:00paul.j3setmessages: + msg368215
2020-04-28 15:50:18paul.j3setmessages: + msg367537
2020-04-28 12:45:45xtreaksetnosy: + rhettinger, paul.j3
2020-04-28 12:34:22Leonid Ilyevskycreate