New submission from Krzysiek <[email protected]>:
The documentation for `ArgumentParser.add_mutually_exclusive_group` states:
"argparse will make sure that only one of the arguments in the mutually
exclusive group was present on the command line".
This is not the case in certain circumstances:
```python
import argparse
parser = argparse.ArgumentParser()
group = parser.add_mutually_exclusive_group()
group.add_argument('-a')
group.add_argument('-b', nargs='?')
parser.parse_args('-a a -b'.split())
```
The above code does not produce any error, even though both exclusive arguments
are present.
My guess is that the check for mutual exclusion is not done during processing
of each command line argument, but rather afterwards. It seems the check only
ensures at most one argument from group is not `None`.
The issue exists at least on Python 2.7.13, 3.6, 3.7.5, 3.8, and 3.10.
----------
components: Library (Lib)
messages: 374065
nosy: kkarbowiak
priority: normal
severity: normal
status: open
title: argparse mutually exclusive group does not exclude in some cases
type: behavior
versions: Python 3.10
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue41359>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com