This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: argparse add_mutually_exclusive_group do not print help
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.2, Python 3.3, Python 3.4, Python 2.7
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Alexandre.Badez, paul.j3
Priority: normal Keywords:

Created on 2015-07-27 12:52 by Alexandre.Badez, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
test_arg.py Alexandre.Badez, 2015-07-27 12:52 bug sample
Messages (4)
msg247465 - (view) Author: Alexandre Badez (Alexandre.Badez) Date: 2015-07-27 12:52
Hi,

Here is a sample of what I do:

>>> import argparse
>>> main_parser = argparse.ArgumentParser()
>>> group_ex = main_parser.add_mutually_exclusive_group()
>>> group_ex1 = group_ex.add_argument_group()
>>> group_ex1.add_argument('-a', '--atest', help="help about -a") and None
>>> group_ex1.add_argument('-b', '--btest', help="help about -b") and None
>>> group_ex.add_argument('-c', '--ctest', help="help about -c") and None
>>> main_parser.print_help()
usage: [-h] [-a ATEST] [-b BTEST] [-c CTEST]

optional arguments:
  -h, --help            show this help message and exit
  -c CTEST, --ctest CTEST
                        help about -c



Here is what I would except as help message:

>>> main_parser.print_help()
usage: [-h] [[-a ATEST] [-b BTEST]] | [-c CTEST]

optional arguments:
  -h, --help            show this help message and exit
  -c CTEST, --ctest CTEST
                        help about -c

  -a ATEST, --atest ATEST
                        help about -a
  -b BTEST, --btest BTEST
                        help about -b

						
Options '-a' and '-b' are not displayed in the help message due to the "add_mutually_exclusive_group".
msg247940 - (view) Author: paul j3 (paul.j3) * (Python triager) Date: 2015-08-03 17:12
These two types of groups serve different purposes and aren't designed to nest or interact.

An argument group groups arguments in the help lines.  It does not affect parsing at all.  It can't be used to add a 'group' of arguments to another group.

A mutually exclusive group produces an error message during parsing, and modifies the usage line.  There isn't a way, in the current code, to nest groups of arguments (in some sort of 'any' or 'and' sense) within a mutually exclusive group.  It's 'xor' for all arguments.
msg248831 - (view) Author: Alexandre Badez (Alexandre.Badez) Date: 2015-08-19 12:45
@paul: thanks, I'm very surprised because the parsing work well.
It's just the display that do not.

Moreover it's not said in the documentation that you cannot nest groups.

So maybe we should update the documentation and/or improve the module ?
msg286583 - (view) Author: paul j3 (paul.j3) * (Python triager) Date: 2017-02-01 02:32
I'm proposing closing this with reference to http://bugs.python.org/issue22047 

That focuses on the issue of adding mutually exclusive group to another exclusive group, but adding Argument Group has the same problems.

Solutions, short of the big http://bugs.python.org/issue11588 fix, include code that raises an error the user attempts to nest groups and/or adding a documentation note that nesting does not work.

There is one kind of nesting that does work - a mutually exclusive group can be nested inside an Argument Group.  The effect is to give the mutually exclusive group a title and help line grouping.
History
Date User Action Args
2022-04-11 14:58:19adminsetgithub: 68924
2017-02-01 02:32:58paul.j3setstatus: open -> closed

messages: + msg286583
2015-08-19 12:45:44Alexandre.Badezsetmessages: + msg248831
2015-08-03 17:12:44paul.j3setnosy: + paul.j3
messages: + msg247940
2015-07-27 12:52:06Alexandre.Badezcreate