diff -r eb1025b107c5 Lib/argparse.py --- a/Lib/argparse.py Mon May 27 23:53:02 2013 -0400 +++ b/Lib/argparse.py Wed Jun 26 23:26:04 2013 -0700 @@ -2236,7 +2236,11 @@ value = action.default else: value = arg_strings - self._check_value(action, value) + if not isinstance(value, list): + self._check_value(action, value) + else: + for v in value: + self._check_value(action, v) # single argument or optional argument produces a single value elif len(arg_strings) == 1 and action.nargs in [None, OPTIONAL]: diff -r eb1025b107c5 Lib/test/test_argparse.py --- a/Lib/test/test_argparse.py Mon May 27 23:53:02 2013 -0400 +++ b/Lib/test/test_argparse.py Wed Jun 26 23:26:04 2013 -0700 @@ -820,6 +820,44 @@ ] +class TestPositionalsNargsZeroOrMoreChoices(ParserTestCase): + """Test a Positional that specifies unlimited nargs with choices""" + + argument_signatures = [Sig('foo', nargs='*', choices='abc')] + failures = ['-x', 'spam'] + successes = [ + ('', NS(foo=[])), + ('a', NS(foo=['a'])), + ('a b', NS(foo=['a', 'b'])), + ] + + +class TestPositionalsNargsZeroOrMoreChoicesDefault1(ParserTestCase): + """Test a Positional that specifies unlimited nargs with choices""" + + argument_signatures = [Sig('foo', nargs='*', choices='abc', default='c')] + failures = ['-x', 'spam'] + successes = [ + ('', NS(foo='c')), + ('a', NS(foo=['a'])), + ('a b', NS(foo=['a', 'b'])), + ] + + + +class TestPositionalsNargsZeroOrMoreChoicesDefault2(ParserTestCase): + """Test a Positional that specifies unlimited nargs with choices""" + + argument_signatures = [Sig('foo', nargs='*', choices='abc', default=['a', 'b'])] + failures = ['-x', 'spam'] + successes = [ + ('', NS(foo=['a', 'b'])), + ('a', NS(foo=['a'])), + ('a b', NS(foo=['a', 'b'])), + ] + + + class TestPositionalsNargsOneOrMore(ParserTestCase): """Test a Positional that specifies one or more nargs""" @@ -831,6 +869,17 @@ ] +class TestPositionalsNargsOneOrMoreChoices(ParserTestCase): + """Test a Positional that specifies one or more nargs with choices""" + + argument_signatures = [Sig('foo', nargs='+', choices='abc')] + failures = ['', '-x', 'spam'] + successes = [ + ('a', NS(foo=['a'])), + ('a b', NS(foo=['a', 'b'])), + ] + + class TestPositionalsNargsOptional(ParserTestCase): """Tests an Optional Positional"""