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 chris.jerdonek
Recipients bethard, chris.jerdonek, r.david.murray, terry.reedy
Date 2013-01-26.23:05:00
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1359241500.95.0.499906229698.issue16468@psf.upfronthosting.co.za>
In-reply-to
Content
> the choice part of the error message (passed to ArgumentError) will just be 'invalid choice: <value>'.

That's right.  With the patch it looks like this:

>>> p = argparse.ArgumentParser(prog='test.py')
>>> p.add_argument('--foo', choices=c)
>>> p.parse_args(['--foo', 'bad'])
usage: test.py [-h] [--foo FOO]
test.py: error: argument --foo: invalid choice: 'bad'

> With that, using default metavars, whatever they end up being

argparse's default metavar is just to capitalize the "dest" if the argument is optional, otherwise it is the dest itself (which is always or usually lower-case):

    def _get_default_metavar_for_optional(self, action):
        return action.dest.upper()

    def _get_default_metavar_for_positional(self, action):
        return action.dest

So the patch uses that.  You can see the former case in the above usage string.  Also, with the patch the current tests pass, btw.
History
Date User Action Args
2013-01-26 23:05:01chris.jerdoneksetrecipients: + chris.jerdonek, terry.reedy, bethard, r.david.murray
2013-01-26 23:05:00chris.jerdoneksetmessageid: <1359241500.95.0.499906229698.issue16468@psf.upfronthosting.co.za>
2013-01-26 23:05:00chris.jerdoneklinkissue16468 messages
2013-01-26 23:05:00chris.jerdonekcreate