paul j3 added the comment:
A possibly unintended consequence to this `seen_non_default_actions` testing is
that default values do not qualify as 'present' when testing for a required
mutually exclusive group.
p=argparse.ArgumentParser()
g=p.add_mutually_exclusive_group(required=True)
g.add_argument('--foo',default='test')
g.add_argument('--bar',type=int,default=42)
p.parse_args('--bar 42'.split())
raises an `error: one of the arguments --foo --bar is required`
In the original code
p.parse_args('--foo test'.split())
does not raise an error because 'test' does not qualify as default. But with
the change I proposed, it does raise the error.
This issue may require adding a `failures_when_required` category to the
test_argparse.py MEMixin class. Currently nothing in test_argparse.py tests
for this issue.
Note that this contrasts with the handling of ordinarily required arguments.
p.add_argument('--baz',type=int,default=42,required=True)
'--baz 42' does not raise an error. It is 'present' regardless of whether its
value matches the default or not.
This argues against tightening the `seen_non_default_actions` test. Because
the current testing only catches a few defaults (None and small ints) it is
likely that no user has come across the required group issue. There might
actually be fewer compatibility issues if we simply drop the default test (or
limit it to the case where the default=None).
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue18943>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com