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 Clint Olsen, eric.smith, paul.j3
Date 2021-05-04.21:13:34
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1620162814.22.0.475838391855.issue43192@roundup.psfhosted.org>
In-reply-to
Content
To a large degree the Action parameters operate independently.  That is, different parts of the code use the parameters for their own purposes. The composite behavior is a result of those individual actors, rather than some sort of overall coordinated plan.

First your Action is 'positional' (no flag string), and "store" type.  nargs is the default None.  The only extra is the default value (the default default is None).

_ActionsContainer._get_positional_kwargs processes such an argument, setting the 'required' parameter with:

        # mark positional arguments as required if at least one is
        # always required
        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

At the start of parsing, all 'default' values are added to the 'args' Namespace.

If an Action is "seen", either via the appropriate flag string, or a positional value, it is added to the "seen_actions" list.

At the end of parsing, it iterates through all the '_actions'.  If it is not in the 'seen_actions' list, and is marked "required", it gets added to the 'reqiuired_action' error list.

So even though your Action has a 'default' it is still required.  The default is, in effect, ignored.  The nargs value (default or not) has priority in setting the 'required' value.

'?/*' nargs require special handling.  This nargs requirement is satisfied by an empty list.  Such a positional will, in effect, always be seen. But if a explicit default is provided, that will over write the empty list. 

Handling defaults is inherently tricky.  But except for the special '?/*' case, specifying a 'default' with a positional doesn't make much sense.
History
Date User Action Args
2021-05-04 21:13:34paul.j3setrecipients: + paul.j3, eric.smith, Clint Olsen
2021-05-04 21:13:34paul.j3setmessageid: <1620162814.22.0.475838391855.issue43192@roundup.psfhosted.org>
2021-05-04 21:13:34paul.j3linkissue43192 messages
2021-05-04 21:13:34paul.j3create