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.

Author keith
Recipients keith
Date 2021-02-14.06:34:44
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1613284485.11.0.495534943099.issue43220@roundup.psfhosted.org>
In-reply-to
Content
With this code:

```
import argparse

parser = argparse.ArgumentParser()
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument("--foo", default="1")
group.add_argument("--bar")
args = parser.parse_args()
print(args)
```

When you explicitly pass `--foo 1`, it is treated as if no argument was passed:

```
% python3 /tmp/bug.py --foo 1
usage: bug.py [-h] (--foo FOO | --bar BAR)
bug.py: error: one of the arguments --foo --bar is required
```

I can't tell if this behavior is intentional, but it was surprising to me. It also seems to be somewhat based on the length of the default string. For example on my macOS machine if I change the default to `longerstring` it does not have this issue.
History
Date User Action Args
2021-02-14 06:34:45keithsetrecipients: + keith
2021-02-14 06:34:45keithsetmessageid: <1613284485.11.0.495534943099.issue43220@roundup.psfhosted.org>
2021-02-14 06:34:45keithlinkissue43220 messages
2021-02-14 06:34:44keithcreate