homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: argparse.ArgumentParser.add_argument() documentation error
Type: Stage: resolved
Components: Documentation Versions: Python 3.2, Python 3.3, Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, petri.lehtinen, r.david.murray
Priority: normal Keywords: easy

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 "<stdin>", line 1, in <module>
 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:20adminsetgithub: 56923
2011年08月10日 14:38:40r.david.murraysetmessages: + msg141865
2011年08月09日 12:35:08petri.lehtinensetmessages: + msg141816
2011年08月09日 12:24:36r.david.murraysetstatus: open -> closed

nosy: + r.david.murray
messages: + msg141815

resolution: not a bug
stage: resolved
2011年08月09日 11:54:12petri.lehtinencreate

AltStyle によって変換されたページ (->オリジナル) /