New submission from Balázs Regényi:

So, a parent parser is created. It has a "global arguments" group (by 
add_argument_group()) and this group has a mutually exclusive group. Then a 
child parser is created used previous parser as parent. 
The error: in the child parser help: the arguments of the mutually exclusive 
group are printed into the part of child parser instead of their "global 
arguments" group.

The next code shows the problem:

import argparse
# create parent parser
parent_parser = argparse.ArgumentParser(add_help = False)
# create group for its arguments
global_group = parent_parser.add_argument_group("global arguments")
global_group.add_argument("--global-arg1")
global_group.add_argument("--global-arg2")
mutex_group = global_group.add_mutually_exclusive_group()
mutex_group.add_argument("--mutex-arg1")
mutex_group.add_argument("--mutex-arg2")
# create child parser
child_parser = argparse.ArgumentParser(parents = [parent_parser])
child_parser.add_argument("--child-arg1")
child_parser.add_argument("--child-arg2")
print("="*100)
parent_parser.print_help()
print("="*100)
child_parser.print_help()


The output:

====================================================================================================
usage: test.py [--global-arg1 GLOBAL_ARG1] [--global-arg2 GLOBAL_ARG2]
               [--mutex-arg1 MUTEX_ARG1 | --mutex-arg2 MUTEX_ARG2]

global arguments:
  --global-arg1 GLOBAL_ARG1
  --global-arg2 GLOBAL_ARG2
  --mutex-arg1 MUTEX_ARG1
  --mutex-arg2 MUTEX_ARG2
====================================================================================================
usage: test.py [-h] [--global-arg1 GLOBAL_ARG1] [--global-arg2 GLOBAL_ARG2]
               [--mutex-arg1 MUTEX_ARG1 | --mutex-arg2 MUTEX_ARG2]
               [--child-arg1 CHILD_ARG1] [--child-arg2 CHILD_ARG2]

optional arguments:
  -h, --help            show this help message and exit
  --mutex-arg1 MUTEX_ARG1
  --mutex-arg2 MUTEX_ARG2
  --child-arg1 CHILD_ARG1
  --child-arg2 CHILD_ARG2

global arguments:
  --global-arg1 GLOBAL_ARG1
  --global-arg2 GLOBAL_ARG2


The error is that the --mutex-arg-s can be seen in "optional arguments" part 
instead of "global arguments" part in the second (child help) case.
In the first (parent help) case the --mutex-arg-s are printed into the good 
section.

----------
messages: 256518
nosy: balage
priority: normal
severity: normal
status: open
title: argparse help error: arguments created by add_mutually_exclusive_group() 
are shown outside their parent group created by add_argument_group()
type: behavior
versions: Python 2.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue25882>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to