paul j3 added the comment: 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 'argparse.py' runs 'test_argparse.py' without error. This patch does not include the issue18943 changes, which make setting 'seen_non_default_actions' more reliable. ---------- keywords: +patch Added file: http://bugs.python.org/file34176/patch_w_mxg2.diff _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue11588> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com