gh-157127: Reword the argparse mutually exclusive group error message - #157134
Conversation
…usive group error
Documentation build overview
102 files changed ·
|
picnixz
left a comment
There was a problem hiding this comment.
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
|
@picnixz Reworded in 3f7606e: It now matches the error argparse raises a few lines above for plain required arguments, For the other question, here is how three CLIs I checked format it:
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. |
savannahostrowski
left a comment
There was a problem hiding this comment.
Hmm, I agree that the new message is clearer, especially for groups containing a positional, but I’m slightly concerned about the compatibility impact. The existing wording is documented and has existed since argparse was added in 2010. A quick GitHub scan found downstream projects with exact-string assertions, as well as translation catalogs containing the existing message ID.
That said, since this would land early in the 3.16 development cycle, I think we have enough time to try it and receive feedback before the release.
When a required mutually exclusive group is not satisfied, argparse joins the
argument names with a plain space:
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 themwith
', '. This makes the mutually exclusive group error do the same:The doc example and the three affected test assertions are updated to match.
Fixes #157127