Author thesociable
Recipients bethard, eric.araujo, eric.smith, regis, thesociable
Date 2012-01-23.22:23:14
SpamBayes Score 1.03048e-07
Marked as misclassified No
Message-id <>
The real issue is that the choices flag does not work with a default flag and * nargs.

The following works as expected:
>>> parser.add_argument('chosen', nargs='*', default=['a'])
>>> print(parser.parse_args())
>>> print(parser.parse_args(['a', 'b']))
Namespace(chosen=['a', 'b'])

Introducing a choices constraint breaks down when using the defaults:
>>> parser.add_argument('chosen', nargs='*', default=['a'], choices=['a', 'b'])
>>> print(parser.parse_args(['a']))
>>> print(parser.parse_args())
error: argument chosen: invalid choice: ['a'] (choose from 'a', 'b')

I would expect instead to have Namespace.chosen populated with the default list as before, but the choices constraint check does not validate correctly.

I think that changing the choices constraint logic to iterate over the default values if nargs results in a list would be a possible solution.
Date User Action Args
2012-01-23 22:23:15thesociablesetrecipients: + thesociable, bethard, eric.smith, eric.araujo, regis
2012-01-23 22:23:15thesociablesetmessageid: <>
2012-01-23 22:23:14thesociablelinkissue9625 messages
2012-01-23 22:23:14thesociablecreate