homepage

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 should allow displaying argument default values in addition to setting a formatter class
Type: enhancement Stage: test needed
Components: Library (Lib) Versions: Python 3.5
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: bethard, denilsonsa, paul.j3, zbysz
Priority: normal Keywords:

Created on 2011年09月20日 22:28 by denilsonsa, last changed 2022年04月11日 14:57 by admin.

Messages (4)
msg144354 - (view) Author: Denilson Figueiredo de Sá (denilsonsa) Date: 2011年09月20日 22:28
In my script, I wanted two things at the same time:
1. Setting a formatter class so that the epilog would have the line breaks preserved.
2. Telling argparse to automatically display default values for all arguments.
Currently, both things are handled by the same configuration parameter: formatter_class
This means we can either pass argparse.RawDescriptionHelpFormatter or argparse.ArgumentDefaultsHelpFormatter, but not both.
I did a hackish workaround by subclassing both formatters, and passing my (empty) subclass to ArgumentParser. It works for now, but it might break on future versions.
The ideal solution, however, would have a native support for both features, or at least explicitly allowing subclassing.
Maybe ArgumentDefaultsHelpFormatter could be transformed into a simple boolean parameter passed to ArgumentParser object (and maybe also passed to add_argument() method), instead of being a formatter class.
msg144475 - (view) Author: Zbyszek Jędrzejewski-Szmek (zbysz) * Date: 2011年09月23日 21:04
Yeah, adding a formatter instance seems overkill for the usual case of wanting to preserver formatting of the epilog.
msg144500 - (view) Author: Denilson Figueiredo de Sá (denilsonsa) Date: 2011年09月24日 15:54
> adding a formatter instance seems overkill for the usual case of
> wanting to preserve formatting of the epilog.
Related bug (look at it before (re)designing the API):
http://bugs.python.org/issue12806 
msg149537 - (view) Author: Steven Bethard (bethard) * (Python committer) Date: 2011年12月15日 12:05
Your solution is actually the current recommended solution - mix together both classes that you want to combine and pass your subclass as the parameter. This should probably be documented somewhere (and tested more).
History
Date User Action Args
2022年04月11日 14:57:21adminsetgithub: 57232
2014年07月16日 13:09:35BreamoreBoysetnosy: + paul.j3

versions: + Python 3.5, - Python 3.3
2011年12月15日 12:05:44bethardsetmessages: + msg149537
2011年09月24日 15:54:52denilsonsasetmessages: + msg144500
2011年09月23日 21:04:26zbyszsetnosy: + zbysz
messages: + msg144475
2011年09月23日 19:39:25terry.reedysetnosy: + bethard
stage: test needed

versions: - Python 2.7, Python 3.2, Python 3.4
2011年09月20日 22:28:26denilsonsacreate

AltStyle によって変換されたページ (->オリジナル) /