New submission from Cyker Way:
Using `choices` option in `argparse` module caused unwanted behavior.
# Without `choices`
parser = argparse.ArgumentParser()
parser.add_argument('length')
parser.print_help()
## Output
usage: demo.py [-h] length
positional arguments:
length
optional arguments:
-h, --help show this help message and exit
# With choices
parser = argparse.ArgumentParser()
parser.add_argument('length', choices=[1,2,3])
parser.print_help()
## Output
usage: demo.py [-h] {1,2,3}
positional arguments:
{1,2,3}
optional arguments:
-h, --help show this help message and exit
I think the doc says ArgumentParser objects use the `dest` value as the “name”
of each object. And the doc doesn't mention anything about `dest` be changed by
`choices`. The help text looks ugly when there is a long list of choices.
Currently the problem can be remedied by adding a `metavar` option. But I hope
it will be fixed in the library itself.
----------
components: Library (Lib)
messages: 283713
nosy: cyker
priority: normal
severity: normal
status: open
title: argparse: choices override metavar
type: behavior
versions: Python 3.5
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue29030>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com