Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

argparse add_mutually_exclusive_group do not print help #68924

Closed
AlexandreBadez mannequin opened this issue Jul 27, 2015 · 4 comments
Closed

argparse add_mutually_exclusive_group do not print help #68924

AlexandreBadez mannequin opened this issue Jul 27, 2015 · 4 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@AlexandreBadez
Copy link
Mannequin

AlexandreBadez mannequin commented Jul 27, 2015

BPO 24736
Files
  • test_arg.py: bug sample
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2017-02-01.02:32:58.797>
    created_at = <Date 2015-07-27.12:52:06.663>
    labels = ['type-bug', 'library']
    title = 'argparse add_mutually_exclusive_group do not print help'
    updated_at = <Date 2017-02-01.02:32:58.796>
    user = 'https://bugs.python.org/AlexandreBadez'

    bugs.python.org fields:

    activity = <Date 2017-02-01.02:32:58.796>
    actor = 'paul.j3'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-02-01.02:32:58.797>
    closer = 'paul.j3'
    components = ['Library (Lib)']
    creation = <Date 2015-07-27.12:52:06.663>
    creator = 'Alexandre.Badez'
    dependencies = []
    files = ['40038']
    hgrepos = []
    issue_num = 24736
    keywords = []
    message_count = 4.0
    messages = ['247465', '247940', '248831', '286583']
    nosy_count = 2.0
    nosy_names = ['Alexandre.Badez', 'paul.j3']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue24736'
    versions = ['Python 2.7', 'Python 3.2', 'Python 3.3', 'Python 3.4']

    @AlexandreBadez
    Copy link
    Mannequin Author

    AlexandreBadez mannequin commented Jul 27, 2015

    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".

    @AlexandreBadez AlexandreBadez mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Jul 27, 2015
    @paulj3
    Copy link
    Mannequin

    paulj3 mannequin commented Aug 3, 2015

    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.

    @AlexandreBadez
    Copy link
    Mannequin Author

    AlexandreBadez mannequin commented Aug 19, 2015

    @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 ?

    @paulj3
    Copy link
    Mannequin

    paulj3 mannequin commented Feb 1, 2017

    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.

    @paulj3 paulj3 mannequin closed this as completed Feb 1, 2017
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    0 participants