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: Suggestion to improve argparse's help messages for "store_const"
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.3
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Amnon.Harel, bethard
Priority: normal Keywords:

Created on 2012-04-05 08:34 by Amnon.Harel, last changed 2022-04-11 14:57 by admin.

Files
File name Uploaded Description Edit
demo.py Amnon.Harel, 2012-04-05 08:34
Messages (2)
msg157554 - (view) Author: Amnon Harel (Amnon.Harel) Date: 2012-04-05 08:34
argparse's help messages for variables that use "store_const" can probably be improved:
- propagate the default to all the options
- mark the default option as such explicitly
- group the keywords that have the same destination together (?)
- place the default option first (?)

For example, wouldn't the attached .py be better served with a help message that looks like:
...
optional arguments:
  -h, --help         show this help message and exit
  -w, --wrench       use a wrench (default)
  -H, --hammer       use a hammer (default: wrench)
  -s, --screwdriver  use a screwdriver (default: wrench)
  -T, --tnt          just blow the whole thing up (default: wrench)
  --foo FOO          foo bar (default: None)

?
msg166064 - (view) Author: Steven Bethard (bethard) * (Python committer) Date: 2012-07-21 20:38
Special casing the formatting of 'store_const' makes me nervous because formatting is already complicated and it doesn't know anything about action types.

But feel free to propose a patch!

In the meantime:

- propagate the default to all the options

You can, of course, do this manually, by specifying default in each of them. And if you use formatter_class=ArgumentDefaultsHelpFormatter, you'll get the defaults in the usage message.

- group the keywords that have the same destination together (?)
- place the default option first (?)

You can achieve both of these by just adding the options in the order that you want them displayed.
History
Date User Action Args
2022-04-11 14:57:28adminsetgithub: 58709
2012-07-21 20:38:59bethardsetmessages: + msg166064
2012-04-05 13:00:44r.david.murraysetnosy: + bethard

versions: + Python 3.3, - Python 2.7
2012-04-05 08:34:11Amnon.Harelcreate