[New-bugs-announce] [issue24441] In argparse add_argument() allows the empty choices argument
py.user
report at bugs.python.org
Fri Jun 12 23:41:11 CEST 2015
New submission from py.user:
A script, configuring argparse to have no choices:
#!/usr/bin/env python3
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('foo', choices=[])
args = parser.parse_args()
print(args)
Running it:
[guest at localhost args]$ ./t.py
usage: t.py [-h] {}
t.py: error: too few arguments
[guest at localhost args]$ ./t.py a
usage: t.py [-h] {}
t.py: error: argument foo: invalid choice: 'a' (choose from )
[guest at localhost args]$ ./t.py ""
usage: t.py [-h] {}
t.py: error: argument foo: invalid choice: '' (choose from )
[guest at localhost args]$
[guest at localhost args]$ ./t.py -h
usage: t.py [-h] {}
positional arguments:
{}
optional arguments:
-h, --help show this help message and exit
[guest at localhost args]$
ISTM, it should throw an exception about empty choices rather than show help with empty choices.
----------
components: Library (Lib)
messages: 245277
nosy: py.user
priority: normal
severity: normal
status: open
title: In argparse add_argument() allows the empty choices argument
type: behavior
versions: Python 3.3, Python 3.6
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue24441>
_______________________________________
More information about the New-bugs-announce
mailing list