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 Jan Hutař
Recipients Jan Hutař, Sworddragon, berker.peksag, bethard, ced, eric.araujo, eric.smith, lanzz, macfreek, paul.j3, regis, rhettinger, sebix, thesociable
Date 2019-11-20.11:55:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1574250954.15.0.923502030356.issue9625@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2019-11-20 11:55:54Jan Hutařsetrecipients: + Jan Hutař, rhettinger, bethard, macfreek, eric.smith, eric.araujo, ced, Sworddragon, thesociable, regis, berker.peksag, paul.j3, sebix, lanzz
2019-11-20 11:55:54Jan Hutařsetmessageid: <1574250954.15.0.923502030356.issue9625@roundup.psfhosted.org>
2019-11-20 11:55:54Jan Hutařlinkissue9625 messages
2019-11-20 11:55:53Jan Hutařcreate