[issue9625] argparse: Problem with defaults for variable nargs when using choices

Mihail Milushev report at bugs.python.org
Mon Nov 18 06:14:30 EST 2019


Mihail Milushev <python.org at site.lanzz.org> added the comment:

It looks like choices are broken for nargs='*' even without using default:

>>> import argparse
>>> parser = argparse.ArgumentParser()
>>> parser.add_argument('test', nargs='*', choices=['foo', 'bar', 'baz'])
_StoreAction(option_strings=[], dest='test', nargs='*', const=None, default=None, type=None, choices=['foo', 'bar', 'baz'], help=None, metavar=None)
>>> parser.parse_args([])
usage: [-h] [{foo,bar,baz} [{foo,bar,baz} ...]]
: error: argument test: invalid choice: [] (choose from 'foo', 'bar', 'baz')

----------
nosy: +lanzz

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue9625>
_______________________________________


More information about the Python-bugs-list mailing list