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@localhost args]$ ./t.py
usage: t.py [-h] {}
t.py: error: too few arguments
[guest@localhost args]$ ./t.py a
usage: t.py [-h] {}
t.py: error: argument foo: invalid choice: 'a' (choose from )
[guest@localhost args]$ ./t.py ""
usage: t.py [-h] {}
t.py: error: argument foo: invalid choice: '' (choose from )
[guest@localhost args]$
[guest@localhost args]$ ./t.py -h
usage: t.py [-h] {}
positional arguments:
{}
optional arguments:
-h, --help show this help message and exit
[guest@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 <[email protected]>
<http://bugs.python.org/issue24441>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com