Index: Lib/test/test_argparse.py =================================================================== --- Lib/test/test_argparse.py (revision 83528) +++ Lib/test/test_argparse.py (working copy) @@ -3782,6 +3782,20 @@ # nargs is always disallowed self.assertTypeError('-x', nargs='*', action=action) + def test_wrong_number_of_metavars(self): + "Verify that a tuple of metavars that disagrees with nargs raises error immediately." + for metavars in ('X', ('X', ), ('X', 'Y'), ('X' ,'Y', 'Z')): + for nargs in (1, 2, 3, '?', '*', '+'): + should_fail = ((isinstance(nargs, int) and len(metavars) > nargs) + or (nargs == '?' and len(metavars) != 1)) + if should_fail: + self.assertValueError('--foo', nargs=nargs, metavar=metavars) + else: + # There's no self.assertNoValueError; I assume that letting the error + # itself propagate is good enough to show an unwanted exception here + parser = argparse.ArgumentParser() + parser.add_argument('--foo', nargs=nargs, metavar=metavars) + def test_more_than_one_argument_actions(self): for action in ['store', 'append']: