Skip to content

Conversation

@paytonward6
Copy link
Contributor

@paytonward6 paytonward6 commented Dec 14, 2023

Prior to fix, a mutually exclusive group that contained a positional would not be printed properly when the positional is not defined first. Instead, it would completely ignore the mutual exclusiveness in the usage output.

For example:

parser = ArgumentParser(prog="PROG")
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument("--foo")
group.add_argument("bar", nargs="?")
parser.parse_args()

would have a usage line of:

usage: PROG [-h] (--foo FOO | bar)

while

parser = ArgumentParser(prog="PROG")
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument("bar", nargs="?")
group.add_argument("--foo")
parser.parse_args()

would have a usage line of:

usage: PROG [-h] [--foo FOO] [bar]

@ghost
Copy link

ghost commented Dec 14, 2023

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-app
Copy link

bedevere-app bot commented Dec 14, 2023

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@paytonward6 paytonward6 changed the title gh-113008: Correct ArgParse usage output for required, mutually exclusive groups gh-113008: Correct argparse usage output for required, mutually exclusive groups Dec 14, 2023
@ghost
Copy link

ghost commented Sep 23, 2024

All commit authors signed the Contributor License Agreement.
CLA signed

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @paytonward6. LGTM.

@serhiy-storchaka
Copy link
Member

There are some conflicts. Please merge the main branch into your branch.

@serhiy-storchaka serhiy-storchaka merged commit d21b0b5 into python:main Sep 24, 2024
34 checks passed
@serhiy-storchaka
Copy link
Member

Thank you for your contribution @paytonward6.

@paytonward6
Copy link
Contributor Author

Thanks for the help @serhiy-storchaka, I appreciate it

@paytonward6 paytonward6 deleted the gh-113008 branch September 24, 2024 20:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants