diff -r 5ef49659935f Lib/argparse.py --- a/Lib/argparse.py Fri Dec 28 19:09:41 2012 +0100 +++ b/Lib/argparse.py Fri Dec 28 20:12:37 2012 -0500 @@ -1397,7 +1397,11 @@ # NOTE: if add_mutually_exclusive_group ever gains title= and # description= then this code will need to be expanded as above for group in container._mutually_exclusive_groups: - mutex_group = self.add_mutually_exclusive_group( + if group._container is container: + cont = self + else: + cont = title_group_map[group._container.title] + mutex_group = cont.add_mutually_exclusive_group( required=group.required) # map the actions to their new mutex group diff -r 5ef49659935f Lib/test/test_argparse.py --- a/Lib/test/test_argparse.py Fri Dec 28 19:09:41 2012 +0100 +++ b/Lib/test/test_argparse.py Fri Dec 28 20:12:37 2012 -0500 @@ -2284,6 +2284,36 @@ -x X '''.format(progname, ' ' if progname else '' ))) + def test_mutex_groups_parents(self): + parent = ErrorRaisingArgumentParser(add_help=False) + g = parent.add_argument_group(title='g', description='gd') + g.add_argument('-w') + g.add_argument('-x') + m = g.add_mutually_exclusive_group() + m.add_argument('-y') + m.add_argument('-z') + parser = ErrorRaisingArgumentParser(parents=[parent]) + + self.assertRaises(ArgumentParserError, parser.parse_args, + ['-y', 'Y', '-z', 'Z']) + + parser_help = parser.format_help() + progname = self.main_program + self.assertEqual(parser_help, textwrap.dedent('''\ + usage: {}{}[-h] [-w W] [-x X] [-y Y | -z Z] + + optional arguments: + -h, --help show this help message and exit + + g: + gd + + -w W + -x X + -y Y + -z Z + '''.format(progname, ' ' if progname else '' ))) + # ============================== # Mutually exclusive group tests # ============================== diff -r 5ef49659935f Misc/ACKS --- a/Misc/ACKS Fri Dec 28 19:09:41 2012 +0100 +++ b/Misc/ACKS Fri Dec 28 20:12:37 2012 -0500 @@ -1159,6 +1159,7 @@ Mark Summerfield Reuben Sumner Marek Ć uppa +Dougal J. Sutherland Hisao Suzuki Kalle Svensson Andrew Svetlov