This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author thesociable
Recipients bethard, eric.araujo, eric.smith, regis, thesociable
Date 2012-01-23.22:23:14
SpamBayes Score 1.0304826e-07
Marked as misclassified No
Message-id <1327357395.1.0.444380733928.issue9625@psf.upfronthosting.co.za>
In-reply-to
Content
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())
Namespace(chosen=['a'])
>>> 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']))
Namespace(chosen=['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.
History
Date User Action Args
2012-01-23 22:23:15thesociablesetrecipients: + thesociable, bethard, eric.smith, eric.araujo, regis
2012-01-23 22:23:15thesociablesetmessageid: <1327357395.1.0.444380733928.issue9625@psf.upfronthosting.co.za>
2012-01-23 22:23:14thesociablelinkissue9625 messages
2012-01-23 22:23:14thesociablecreate