Message180720
> 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. |
|
Date |
User |
Action |
Args |
2013-01-26 23:05:01 | chris.jerdonek | set | recipients:
+ chris.jerdonek, terry.reedy, bethard, r.david.murray |
2013-01-26 23:05:00 | chris.jerdonek | set | messageid: <1359241500.95.0.499906229698.issue16468@psf.upfronthosting.co.za> |
2013-01-26 23:05:00 | chris.jerdonek | link | issue16468 messages |
2013-01-26 23:05:00 | chris.jerdonek | create | |
|