Message374065
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. |
|
Date |
User |
Action |
Args |
2020-07-21 11:46:47 | kkarbowiak | set | recipients:
+ kkarbowiak |
2020-07-21 11:46:47 | kkarbowiak | set | messageid: <1595332007.75.0.283126282834.issue41359@roundup.psfhosted.org> |
2020-07-21 11:46:47 | kkarbowiak | link | issue41359 messages |
2020-07-21 11:46:47 | kkarbowiak | create | |
|