Issue 58 in argparse: Allow title and description arguments for add_mutually_exclusive_group

6 views
Skip to first unread message

argp...@googlecode.com

unread,
Jan 31, 2010, 5:23:00 PM1/31/10
to argpar...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 58 by chphilli: Allow title and description arguments for
add_mutually_exclusive_group
http://code.google.com/p/argparse/issues/detail?id=58

I've been using argparse for a while now, and find that the mutually
exclusive groups are a great idea, but for one lack: I can't take advantage
of argparse's nice group formatting for these groups!

Out of curiosity, I decided to try to make the change myself, and found
that it *seemed* to be relatively simple:
1. Accept "title" and "description" as keyword arguments to
add_mutually_exclusive_group
2. Pass the "title" and "description" as keyword arguments to the super()
call in _MutuallyExclusiveGroup.__init__
3. Add the new group to the parser's action groups in
add_mutually_exclusive_group (e.g., self._action_groups.append(group))

Since this only took about a minute for me to figure out, I feel like there
must be something that I'm missing. If not, could this functionality
be added? If so, what needs to be changed.

(Another thing that makes me curious is that I can't find any requests for
this feature via Google searches... It was the first thing I wanted
after I tried using a mutually exclusive group, so I'm confused as to why
it doesn't appear to be discussed anywhere.)

--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings

argp...@googlecode.com

unread,
Feb 4, 2010, 12:48:45 PM2/4/10
to argpar...@googlegroups.com

Comment #1 on issue 58 by steven.bethard: Allow title and description
arguments for add_mutually_exclusive_group
http://code.google.com/p/argparse/issues/detail?id=58

I think that's basically right - the only thing that really needs to be
done is to
add the arguments to the _MutuallyExclusiveGroup __init__ and then pass
them on the
super() call.

As to why no one else has asked for this, I don't have a good answer. ;-)

I'll get this incorporated into the next version of argparse. If you have
the time to
write a test or two for this behavior and then send me a patch with the
change and
the tests, that would be great.

argp...@googlecode.com

unread,
Mar 1, 2010, 2:11:43 AM3/1/10
to argpar...@googlegroups.com
Updates:
Status: Accepted
Labels: -Type-Defect Type-Enhancement

Comment #2 on issue 58 by steven.bethard: Allow title and description

arguments for add_mutually_exclusive_group
http://code.google.com/p/argparse/issues/detail?id=58

So, I worked on this for a while today, and while I still believe it's
possible, the
suggested change above doesn't work because it breaks the formatting of
regular
groups. If you have a patch that adds this functionality and doesn't break
the
current tests, I'd be happy to look at it.

argp...@googlecode.com

unread,
Jul 23, 2010, 8:51:05 AM7/23/10
to argpar...@googlegroups.com
Updates:
Status: WontFix

Comment #3 on issue 58 by steven.bethard: Allow title and description

arguments for add_mutually_exclusive_group
http://code.google.com/p/argparse/issues/detail?id=58

I'm going to close this as WontFix. There's a pretty straightforward
alternative which is to create a group with a title and description, and
add the mutually exclusive group to that. If you'd like to implement a
patch for the simplified version, please open a new ticket with a patch at
bugs.python.org.

argp...@googlecode.com

unread,
Jul 23, 2010, 10:27:58 AM7/23/10
to argpar...@googlegroups.com

Comment #4 on issue 58 by kewama: Allow title and description arguments for
add_mutually_exclusive_group
http://code.google.com/p/argparse/issues/detail?id=58

Workaround described in comment #3 doesn't seem to support "required=True"
parameter. For example:

=======================================================================
$ cat t.py
#!/build/toolchain/lin32/python-2.6.1/bin/python
import argparse

parser = argparse.ArgumentParser('test')
group = parser.add_argument_group('Verbosities', 'Controls level of output')
mutex_group = group.add_mutually_exclusive_group(required=True)
mutex_group.add_argument('-q', action='store_true', default=False,
help='Quiet mode')
mutex_group.add_argument('-v', action='store_true', default=False,
help='Verbose mode')
args = parser.parse_args()
print 'q=%s v=%s' % (args.q, args.v)
$ ./t.py
q=False v=False
=======================================================================

I would have expected either -q or -v to have been required, i.e. this
behavior:

=======================================================================
$ ./t.py
usage: test [-h] (-q | -v)
test: error: one of the arguments -q -v is required
=======================================================================


argp...@googlecode.com

unread,
Jul 23, 2010, 10:43:44 AM7/23/10
to argpar...@googlegroups.com

Comment #5 on issue 58 by steven.bethard: Allow title and description
arguments for add_mutually_exclusive_group
http://code.google.com/p/argparse/issues/detail?id=58

Well that looks like a bug. Could you please file a bug on bugs.python.org?
This bug tracker is no longer in use. Thanks!

argp...@googlecode.com

unread,
Apr 3, 2013, 1:18:14 PM4/3/13
to argpar...@googlegroups.com

Comment #6 on issue 58 by damien.n...@gmail.com: Allow title and
description arguments for add_mutually_exclusive_group
http://code.google.com/p/argparse/issues/detail?id=58

Hi Steven,

I am sorry to comment on something closed for so long.
http://bugs.python.org/issue10680 is resolved in python 2.7
Can we please port the fix here so it is available for python <= 2.6?

Thank you.

--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings
Reply all
Reply to author
Forward
0 new messages