Issue 12714: argparse.ArgumentParser.add_argument() documentation error (original) (raw)

Issue12714

Created on 2011-08-09 11:54 by petri.lehtinen, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (4)
msg141812 - (view) Author: Petri Lehtinen (petri.lehtinen) * (Python committer) Date: 2011-08-09 11:54
The documentation of argparse.ArgumentParser.add_argument() says: * required - Whether or not the command-line option may be omitted (optionals only). I believe it should be "options only" instead of "optionals only".
msg141815 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2011-08-09 12:24
Nope, optionals is what argparse calls them.
msg141816 - (view) Author: Petri Lehtinen (petri.lehtinen) * (Python committer) Date: 2011-08-09 12:35
Yes, but required=True/False makes an *option* required or optional. Setting required=False is not allowed with *positionals*: >>> import argparse >>> parser = argparse.ArgumentParser() >>> parser.add_argument('foo', required=False) Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.7/argparse.py", line 1262, in add_argument kwargs = self._get_positional_kwargs(*args, **kwargs) File "/usr/lib/python2.7/argparse.py", line 1367, in _get_positional_kwargs raise TypeError(msg) TypeError: 'required' is an invalid argument for positionals I assume that this is the case that is being documented here, so it should read "options only" meaning "not allowed for positionals". Am I correct?
msg141865 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2011-08-10 14:38
"optionals only" means the same thing as "options only", but 'optionals' is what argparse calls them (as contrasted with positionals). 'optionals' is only used two places in the doc and isn't defined, but its meaning is implied by the section heading ("optional arguments").
History
Date User Action Args
2022-04-11 14:57:20 admin set github: 56923
2011-08-10 14:38:40 r.david.murray set messages: +
2011-08-09 12:35:08 petri.lehtinen set messages: +
2011-08-09 12:24:36 r.david.murray set status: open -> closednosy: + r.david.murraymessages: + resolution: not a bugstage: resolved
2011-08-09 11:54:12 petri.lehtinen create