You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A mutually exclusive group can handle only one positional argument, and it should be the last one added to the group.. I don't recall if that's more a limitation in the testing or the usage. Usage formatting is know to be brittle, especially with regard to the MXGs.
A bare '-' dest is not encouraged. It may be possible, but usually should something like '-f', dash plus single character.
Usage formatting needs a complete rewrite - one of these days.
Fixed in 3.14. Not sure if it's worth doing the backport -- it's only a minor improvement to the help output, and there's already a known workaround.
As for the original example, I do not recommend to use option "-" to solve this problem. It would work weird if you have more than one positional arguments. It is easier to simply check the positional argument value after parsing:
Bug report
Bug description:
I'm defining a argparse parser that works like vim:
So I write a mutually exclusive group:
When I use "-h" to show the help message, the "|" in usage line is dropped, as if the 2 arguments are not mutually exclusive:
However, if I swap the 2
add_argument
lines in the source code:It magically behaves correctly:
CPython versions tested on:
3.9, 3.11
Operating systems tested on:
Windows
Linked PRs
The text was updated successfully, but these errors were encountered: