Skip to content

gh-157127: Reword the argparse mutually exclusive group error message - #157134

Open
lazerg wants to merge 2 commits into
python:mainfrom
lazerg:fix-issue-157127
Open

gh-157127: Reword the argparse mutually exclusive group error message#157134
lazerg wants to merge 2 commits into
python:mainfrom
lazerg:fix-issue-157127

Conversation

@lazerg

@lazerg lazerg commented Sep 7, 2026

Copy link
Copy Markdown

When a required mutually exclusive group is not satisfied, argparse joins the
argument names with a plain space:

error: one of the arguments --stdout repository is required

With a positional in the group this reads as broken grammar, since nothing
separates one name from the next.

The error for missing required arguments a few lines above in
_parse_known_args() puts its names at the end of the sentence and joins them
with ', '. This makes the mutually exclusive group error do the same:

error: one of the following arguments is required: --stdout, repository

The doc example and the three affected test assertions are updated to match.

Fixes #157127

@read-the-docs-community

read-the-docs-community Bot commented Sep 7, 2026

Copy link
Copy Markdown

@picnixz picnixz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I suggest to reweite the error message as follows: "one of the following arguments is required: arg1, arg2, arg3".

Otherwise could we have some examples of what other CLIs in other packages format such errors (if any?) it would be good to take inspiration from them when possible

@lazerg lazerg changed the title gh-157127: Separate names with commas in argparse mutually exclusive group error gh-157127: Reword the argparse mutually exclusive group error message Sep 9, 2026
@lazerg

lazerg commented Sep 9, 2026

Copy link
Copy Markdown
Author

@picnixz Reworded in 3f7606e:

PROG: error: one of the following arguments is required: --foo, --bar

It now matches the error argparse raises a few lines above for plain required arguments, the following arguments are required: --foo, --bar, so the two read the same way.

For the other question, here is how three CLIs I checked format it:

  • Cobra (docker, kubectl, gh): at least one of the flags in the group [--foo --bar] is required
  • clap (Rust): the following required arguments were not provided:, then <--foo|--bar> on the next line
  • argparse itself, non-exclusive case: the following arguments are required: --foo, --bar

All three put the names at the end and keep a visible separator between them. Brackets, pipes or commas, but never a bare space. The new message follows that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

argparse exclusive argument group error unintelligible

2 participants