Author keith
Recipients keith
Date 2021-02-14.06:34:44
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
With this code:

import argparse

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

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

% python3 /tmp/ --foo 1
usage: [-h] (--foo FOO | --bar BAR) 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.
Date User Action Args
2021-02-14 06:34:45keithsetrecipients: + keith
2021-02-14 06:34:45keithsetmessageid: <>
2021-02-14 06:34:45keithlinkissue43220 messages
2021-02-14 06:34:44keithcreate