diff -r 9ea84f006892 Lib/argparse.py --- a/Lib/argparse.py Wed May 01 15:15:50 2013 +0200 +++ b/Lib/argparse.py Wed Jul 03 14:33:46 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 9ea84f006892 Lib/test/test_argparse.py --- a/Lib/test/test_argparse.py Wed May 01 15:15:50 2013 +0200 +++ b/Lib/test/test_argparse.py Wed Jul 03 14:33:46 2013 -0700 @@ -820,6 +820,44 @@ ] +class TestPositionalsNargsZeroOrMoreChoices(ParserTestCase): + """Test a Positional that specifies unlimited nargs with choices""" + + argument_signatures = [Sig('foo', nargs='*', choices=['a', 'b', 'c'])] + 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=['a', 'b', 'c'], 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=['a', 'b', 'c'], 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=['a', 'b', 'c'])] + failures = ['', '-x', 'spam'] + successes = [ + ('a', NS(foo=['a'])), + ('a b', NS(foo=['a', 'b'])), + ] + + class TestPositionalsNargsOptional(ParserTestCase): """Tests an Optional Positional"""