Message219660
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. |
|
Date |
User |
Action |
Args |
2014-06-03 05:44:01 | paul.j3 | set | recipients:
+ paul.j3, bethard, gotgenes, micktwomey, jamadagni |
2014-06-03 05:44:01 | paul.j3 | set | messageid: <1401774241.04.0.329172604401.issue10984@psf.upfronthosting.co.za> |
2014-06-03 05:44:01 | paul.j3 | link | issue10984 messages |
2014-06-03 05:44:00 | paul.j3 | create | |
|