[issue11588] Add "necessarily inclusive" groups to argparse

paul j3 report at bugs.python.org
Mon May 16 17:52:31 EDT 2016


paul j3 added the comment:

So far I've proposed adding a 'hook' at the end of '_parse_known_args', that would give the user access to the 'seen_non_default_actions' variable.  This function could perform an almost arbitrarily complex set of logical co-occurrence tests on this set (or list) of Actions.

The rest of my proposed patches (nested groups, etc) are user interface components that attempt make this testing more user-friendly, both in specification and usage display.

It just occurred to me that an alternate stop-gap fix is to make 'seen_non_default_actions' available to the user for his own testing after parsing.  Adding it to the method return is not backward compatible.  But it could be added as an attribute to parser.

     self._seen_actions = seen_non_default_actions

It would be the first case of giving the parser a memory of past parsing actions, but I don't think that's a problem.

Another possibility is to conditionally add it to the 'namespace'. 

     if hasattr(namespace, 'seen_actions'):
        setattr(namespace, 'seen_actions', seen_non_default_actions)

The user could initial this attribute with a custom 'Namespace' object or with a 'set_defaults' call.

(I'm  proposing to save 'seen_non_default_actions' because in my earlier tests that seemed to be more useful than 'seen_actions'.  It's the one used by mutually_exclusive_group testing.)

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue11588>
_______________________________________


More information about the Python-bugs-list mailing list