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.

Author paul.j3
Recipients elypter, paul.j3
Date 2018-09-27.21:11:14
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1538082674.27.0.545547206417.issue32552@psf.upfronthosting.co.za>
In-reply-to
Content
An alternative to customizing a HelpFormatter is to write your own utility `add_argument` function, e.g.

def my_add_argument(parser, *args, add_default=True, **kwargs):
    if add_default:
        help = kwargs.get('help','')
        help += ' (default: %(default)s)'
        kwargs['help'] = help
    return parser.add_argument(*args, **kwargs)

which could be used as

my_add_argument(parser, '-g', help='bar help', default='other', add_default=False)

There are some refinements to the _get_help_string() that I showed earlier, such as only adding the '%s' to actions where default makes sense (optionals and a subset positionals).  One could also skip it if the default is the default default None, etc.

One way or other the user can already control whether the help line shows the default.  ArgumentDefaultsHelpFormatter just automates this for a straight forward parser.  

I'm going to close this issue since it isn't really needed (and no one has proposed a clever patch).
History
Date User Action Args
2018-09-27 21:11:14paul.j3setrecipients: + paul.j3, elypter
2018-09-27 21:11:14paul.j3setmessageid: <1538082674.27.0.545547206417.issue32552@psf.upfronthosting.co.za>
2018-09-27 21:11:14paul.j3linkissue32552 messages
2018-09-27 21:11:14paul.j3create