Jan Hutař <jhu...@gmail.com> added the comment:

I think there is a same issue with "nargs='+'" - if you are aware of the, 
please ignore me.

$ python3 --version
Python 3.7.5

With "choices=...", there seems to be a problem:


$ cat bbb.py 
#!/usr/bin/env python3

import argparse

parser = argparse.ArgumentParser()
parser.add_argument('choices', nargs='*',
                    default=['a', 'b', 'c'],
                    choices=['a', 'b', 'c'])
args = parser.parse_args()

print(args)
$ ./bbb.py 
usage: bbb.py [-h] [{a,b,c} [{a,b,c} ...]]
bbb.py: error: argument choices: invalid choice: ['a', 'b', 'c'] (choose from 
'a', 'b', 'c')
$ ./bbb.py a c
Namespace(choices=['a', 'c'])


but without choices it works:


$ cat bbb.py 
#!/usr/bin/env python3

import argparse

parser = argparse.ArgumentParser()
parser.add_argument('choices', nargs='*',
                    default=['a', 'b', 'c'])
args = parser.parse_args()

print(args)
$ ./bbb.py 
Namespace(choices=['a', 'b', 'c'])
$ ./bbb.py a c
Namespace(choices=['a', 'c'])


As I said, if this is a known issue, I'm sorry for the noise.

----------
nosy: +Jan Hutař

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue9625>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to