bug in mutual exclusion usage display

12 views
Skip to first unread message

Nullset

unread,
Oct 13, 2010, 5:16:55 AM10/13/10
to argparse-users
When defining multiple mutual exclusion groups, each successive group
is nested in the previous group's square brackets when printed in the
usage blurb. It does not appear to have any effect on the logic - just
the display.

Example (redacted):

parser = argparse.ArgumentParser(description='...', epilog='...')

prompt_group = parser.add_mutually_exclusive_group()
prompt_group.add_argument('-f','--force', action='store_true')
prompt_group.add_argument('-i', action='store_true', default=True)
prompt_group.add_argument('-I', action='store_true')
prompt_group.add_argument('--interactive', action='store',
metavar='WHEN', choices=['never','once','always'])

dereference_group = parser.add_mutually_exclusive_group()
dereference_group.add_argument('-H', action='store_true')
dereference_group.add_argument('-L','--dereference',
action='store_true')
dereference_group.add_argument('-P','--no-dereference',
action='store_true', default=True)

preserve_root_group = parser.add_mutually_exclusive_group()
preserve_root_group.add_argument('--no-preserve-root',
action='store_true')
preserve_root_group.add_argument('--preserve-root',
action='store_true', default=True)

parser.add_argument('SOURCE', action='append', nargs='+')

When run:
$ prog --help

Produces:

usage: prog [-h]
[-f | -i | -I | --interactive WHEN [-H | -L | -P [--no-
preserve-root | --preserve-root]
SOURCE [SOURCE ...]

...

positional arguments:
SOURCE

optional arguments:
-h, --help show this help message and exit
-f, --force ...
-i ...
-I ...
--interactive WHEN ...
-H ...
-L, --dereference ...
-P, --no-dereference ...
--no-preserve-root ...
--preserve-root ...

...

Steven Bethard

unread,
Oct 13, 2010, 11:12:56 AM10/13/10
to argpars...@googlegroups.com
On Wed, Oct 13, 2010 at 11:16 AM, Nullset <cxza...@gmail.com> wrote:
> When defining multiple mutual exclusion groups, each successive group
> is nested in the previous group's square brackets when printed in the
> usage blurb. It does not appear to have any effect on the logic - just
> the display.

I believe this is the problem reported here:

http://bugs.python.org/issue9355

As soon as I can get some time for argparse, I'll commit this fix.

Steve
--
Where did you get that preposterous hypothesis?
Did Steve tell you that?
        --- The Hiphopopotamus

Reply all
Reply to author
Forward
0 new messages