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 cykerway, paul.j3, r.david.murray
Date 2017-01-06.21:44:59
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1483739099.37.0.839355045314.issue29030@psf.upfronthosting.co.za>
In-reply-to
Content
Here's the method in HelpFormatter that creates the metavar:

    def _metavar_formatter(self, action, default_metavar):
        if action.metavar is not None:
            result = action.metavar
        elif action.choices is not None:
            choice_strs = [str(choice) for choice in action.choices]
            result = '{%s}' % ','.join(choice_strs)
        else:
            result = default_metavar

        def format(tuple_size):
            if isinstance(result, tuple):
                return result
            else:
                return (result, ) * tuple_size
        return format

So in order of priority it uses: 

    the explicit metavar parameter
    formatted choices
    a default metavar (normally derived from the dest)

The MetavarTypeHelpFormatter subclass changes how that default is derived.  In the same spirit, you could write your own Formatter subclass that changes the above method, and its priority order.

In your example, the use of choices in the 'usage' like looks good to me.  I agree that its use in the 'help' line does not look so good.  But don't forget that for your end user, the positional 'dest' (or name) has no value.  Only you as the programmer sees and uses it.

This is one of many implementation details that could be included in the argparse docs.  But for some users those docs are already too complex.  The existing docs are not a formal module reference.
History
Date User Action Args
2017-01-06 21:44:59paul.j3setrecipients: + paul.j3, r.david.murray, cykerway
2017-01-06 21:44:59paul.j3setmessageid: <1483739099.37.0.839355045314.issue29030@psf.upfronthosting.co.za>
2017-01-06 21:44:59paul.j3linkissue29030 messages
2017-01-06 21:44:59paul.j3create