[New-bugs-announce] [issue41854] argparse.add_mutually_exclusive_group fails for optional positional arguments
Reuben Thomas
report at bugs.python.org
Thu Sep 24 16:23:50 EDT 2020
New submission from Reuben Thomas <rrt at sc3d.org>:
The following code:
group = parser.add_mutually_exclusive_group()
group.add_argument('--install-only', action='store_true',
help='just install the program, do not run it')
group.add_argument('args', metavar='ARGUMENT', nargs='*', default=None,
help='arguments to PROGRAM')
gives the following error:
group.add_argument('args', metavar='ARGUMENT', nargs='*',
File "/usr/lib/python3.8/argparse.py", line 1398, in add_argument
return self._add_action(action)
File "/usr/lib/python3.8/argparse.py", line 1621, in _add_action
raise ValueError(msg)
ValueError: mutually exclusive arguments must be optional
But the 'args' argument *is* optional, as there can be 0 of them.
----------
components: Library (Lib)
messages: 377460
nosy: rrt
priority: normal
severity: normal
status: open
title: argparse.add_mutually_exclusive_group fails for optional positional arguments
versions: Python 3.8
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41854>
_______________________________________
More information about the New-bugs-announce
mailing list