Chris Jerdonek added the comment:

> 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.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue16468>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to