Author paul.j3
Recipients arigo, bethard, paul.j3, pitrou
Date 2013-09-08.16:12:21
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1378656742.04.0.132317284171.issue18943@psf.upfronthosting.co.za>
In-reply-to
Content
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).
History
Date User Action Args
2013-09-08 16:12:22paul.j3setrecipients: + paul.j3, arigo, pitrou, bethard
2013-09-08 16:12:22paul.j3setmessageid: <1378656742.04.0.132317284171.issue18943@psf.upfronthosting.co.za>
2013-09-08 16:12:22paul.j3linkissue18943 messages
2013-09-08 16:12:21paul.j3create