Message151857
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. |
|
Date |
User |
Action |
Args |
2012-01-23 22:23:15 | thesociable | set | recipients:
+ thesociable, bethard, eric.smith, eric.araujo, regis |
2012-01-23 22:23:15 | thesociable | set | messageid: <1327357395.1.0.444380733928.issue9625@psf.upfronthosting.co.za> |
2012-01-23 22:23:14 | thesociable | link | issue9625 messages |
2012-01-23 22:23:14 | thesociable | create | |
|