Author paul.j3
Recipients John.Didion, bethard, manveru, paul.j3, xuanji
Date 2014-02-21.22:05:30
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
This patch uses:

    tests = self._registries['cross_tests'].values()

to get a list of functions to run at the end of '_parse_known_args'.

I replaced all of the mutually_exclusive_group tests (3 places) in the ArgumentParser with a static function defined in class _MutuallyExclusiveGroup, and registered this function.  This refactoring should make it easier to add other specialized groups (e.g. inclusive) in the future.

I'm using the _registries because they are already being shared among groups.  

A user can also register a custom testing function.  For example:

    def inclusive_test(parser, seen, *args):
        # require an argument from one of the 2 groups, g0 and g1
        g0seen = seen.intersection(g0._group_actions)
        g1seen = seen.intersection(g1._group_actions)
        if len(g0seen.union(g1seen))==0:
            parser.error('one of the 2 groups is required')
    parser.register('cross_tests','inclusive', inclusive_test)

This patched '' runs '' without error.

This patch does not include the issue18943 changes, which make setting 'seen_non_default_actions' more reliable.
Date User Action Args
2014-02-21 22:05:35paul.j3setrecipients: + paul.j3, bethard, xuanji, John.Didion, manveru
2014-02-21 22:05:35paul.j3setmessageid: <>
2014-02-21 22:05:34paul.j3linkissue11588 messages
2014-02-21 22:05:34paul.j3create