New submission from Géry <[email protected]>:
The argparse module incorrectly uses the terms "optional arguments" for keyword
arguments.
For instance this argument parser takes a required keyword argument and an
optional positional argument, but classifies the former as an "optional
argument" and the latter as a "positional argument":
>>> import argparse
>>> parser = argparse.ArgumentParser()
>>> parser.add_argument('--foo', required=True)
_StoreAction(option_strings=['--foo'], dest='foo', nargs=None, const=None,
default=None, type=None, choices=None, help=None, metavar=None)
>>> parser.add_argument('bar', nargs='?')
_StoreAction(option_strings=[], dest='bar', nargs='?', const=None,
default=None, type=None, choices=None, help=None, metavar=None)
>>> parser.parse_args(['-h'])
usage: [-h] --foo FOO [bar]
positional arguments:
bar
optional arguments:
-h, --help show this help message and exit
--foo FOO
Since the actual classification seems to distinguish positional from keyword
arguments instead of required from optional arguments, I think that the
"optional arguments:" section should be renamed to "keyword arguments:".
----------
components: Library (Lib)
messages: 357681
nosy: bethard, maggyero, rhettinger
priority: normal
severity: normal
status: open
title: argparse uses "optional arguments" for "keyword arguments"
type: enhancement
versions: Python 2.7, Python 3.5, Python 3.6, Python 3.7, Python 3.8, Python 3.9
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue38950>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com