Author paul.j3
Recipients bethard, gotgenes, micktwomey, paul.j3
Date 2013-09-02.04:51:50
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
A possible further tweak is, in take_action(), test for conflicts before adding the action to 'seen_non_default_actions'

            if argument_values is not action.default:
                for conflict_action in action_conflicts.get(action, []):
                    if conflict_action in seen_non_default_actions:

This does not cause problems with any existing tests, but makes it possible to add an action twice to a group.  Why do that?  To prevent an action from occurring more than once.  For some actions like 'count' and 'append' repeated use is expected, but for others it isn't expected, and may sometimes be a nuisance (the last occurrence is the one that sticks). 

An example use would be:

    parser = argparse.ArgumentParser(prog="PROG",
    action = parser.add_argument('--arg', help='use this argument only once')
    group1 = parser.add_mutually_exclusive_group(action, action)
    args  = parser.parse_args()

calling this with:

    python3 --arg test --arg next

would produce this error message:

    usage: PROG [-h] [--arg ARG | --arg ARG]
    PROG: error: argument --arg: not allowed with argument --arg

The usage and error message aren't as clear as they might be if this feature was added 'from scratch'.  But for a minor change like this, that may be an acceptable price.
Date User Action Args
2013-09-02 04:51:51paul.j3setrecipients: + paul.j3, bethard, gotgenes, micktwomey
2013-09-02 04:51:51paul.j3setmessageid: <>
2013-09-02 04:51:51paul.j3linkissue10984 messages
2013-09-02 04:51:50paul.j3create