[issue12714] argparse.ArgumentParser.add_argument() documentation error

Petri Lehtinen report at bugs.python.org
Tue Aug 9 14:35:09 CEST 2011


Petri Lehtinen <petri at digip.org> added the comment:

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?

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12714>
_______________________________________


More information about the Python-bugs-list mailing list