Message256518
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. |
|
Date |
User |
Action |
Args |
2015-12-16 13:14:43 | balage | set | recipients:
+ balage |
2015-12-16 13:14:43 | balage | set | messageid: <1450271683.16.0.602190712987.issue25882@psf.upfronthosting.co.za> |
2015-12-16 13:14:43 | balage | link | issue25882 messages |
2015-12-16 13:14:42 | balage | create | |
|