This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author paul.j3
Recipients bethard, chris.jerdonek, paul.j3, r.david.murray
Date 2013-09-18.22:16:56
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1379542617.12.0.892250068954.issue16878@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2013-09-18 22:16:57paul.j3setrecipients: + paul.j3, bethard, r.david.murray, chris.jerdonek
2013-09-18 22:16:57paul.j3setmessageid: <1379542617.12.0.892250068954.issue16878@psf.upfronthosting.co.za>
2013-09-18 22:16:57paul.j3linkissue16878 messages
2013-09-18 22:16:56paul.j3create