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 paul.j3
Recipients bethard, gotgenes, jamadagni, micktwomey, paul.j3
Date 2014-06-03.05:44:00
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1401774241.04.0.329172604401.issue10984@psf.upfronthosting.co.za>
In-reply-to
Content
Another way to add an existing Action to a group is to modify the 'add_argument' method for the Group subclass.  For example we could add this to the _MutuallyExclusiveGroup class:

    def add_argument(self, *args, **kwargs):
        # allow adding a prexisting Action
        if len(args) and isinstance(args[0], Action):
            action =  args[0]
            return self._group_actions.append(action)
        else:
            return super(_MutuallyExclusiveGroup, self).add_argument(*args, **kwargs)

With this the 1st example might be written as:

    group1 = parser.add_mutually_exclusive_group()
    a_action = parser.add_argument('-a')
    c_action = parser.add_argument('-c')
    group2 = parser.add_mutually_exclusive_group()
    group2.add_argument(a_action)
    d_action = parser.add_argument('-d')

This might be more intuitive to users.
History
Date User Action Args
2014-06-03 05:44:01paul.j3setrecipients: + paul.j3, bethard, gotgenes, micktwomey, jamadagni
2014-06-03 05:44:01paul.j3setmessageid: <1401774241.04.0.329172604401.issue10984@psf.upfronthosting.co.za>
2014-06-03 05:44:01paul.j3linkissue10984 messages
2014-06-03 05:44:00paul.j3create