Message198035
On a related point, the 'action.required' value is set differently for '?' and '*' positionals.
if kwargs.get('nargs') not in [OPTIONAL, ZERO_OR_MORE]:
kwargs['required'] = True
if kwargs.get('nargs') == ZERO_OR_MORE and 'default' not in kwargs:
kwargs['required'] = True
OPTIONAL is always not required, ZERO_OR_MORE is not required if it has a default. But for reasons discussed here, that 'required' value makes little difference.
`parse_args` checks that all 'required' arguments have been seen, but a ZERO_OR_MORE positional is always seen (i.e. it matches an empty string).
Usage formatting always uses '[%s [%s ...]]' with ZERO_OR_MORE, regardless of the 'required' attribute.
The only place where this 'required' value seems to matter is when adding such an argument to a mutually exclusive group. But if an unused '*' positional is going to get a '[]' value anyways, why should it be excluded from such a use?
If I remove the
if kwargs.get('nargs') == ZERO_OR_MORE and 'default' not in kwargs:
test, test_argparse.py still runs fine.
http://bugs.python.org/issue18943 is a possibly related issue, involving a 'is not action.default' test in a mutually exclusive group. |
|
Date |
User |
Action |
Args |
2013-09-18 22:16:57 | paul.j3 | set | recipients:
+ paul.j3, bethard, r.david.murray, chris.jerdonek |
2013-09-18 22:16:57 | paul.j3 | set | messageid: <1379542617.12.0.892250068954.issue16878@psf.upfronthosting.co.za> |
2013-09-18 22:16:57 | paul.j3 | link | issue16878 messages |
2013-09-18 22:16:56 | paul.j3 | create | |
|