[issue22363] argparse AssertionError with add_mutually_exclusive_group and help=SUPPRESS

Zacrath report at bugs.python.org
Tue Sep 9 05:22:11 CEST 2014


Zacrath added the comment:

This assert statement is only reached when the usage line is long enough that it needs to be wrapped. Which is why the assertion does not happen when an argument is removed.

opt_usage is being compared to this string:
"[-h] [--arg2 ARG2] [--arg3 ARG3] [--arg4 ARG4] [--arg5 ARG5] [--arg6 ARG6]"

opt_usage in this case has the value:
"[-h]  [--arg2 ARG2] [--arg3 ARG3] [--arg4 ARG4] [--arg5 ARG5] [--arg6 ARG6]"

There is an extra space after "[-h]". The value of opt_usage comes from _format_actions_usage. And that is where the bug is.

Just before _format_actions_usage returns, the usage string is:
"[-h] [ ] [--arg2 ARG2] [--arg3 ARG3] [--arg4 ARG4] [--arg5 ARG5] [--arg6 ARG6]"

The method uses this regexp:
"[ *]"

To remove the extra brackets. But that leaves the extra space after the brackets.

The attached patch changes the regexp to:
"[ *] ?"

So that the extra space is also removed.

The patch also adds a testcase based on the script that reproduces the

----------
keywords: +patch
Added file: http://bugs.python.org/file36579/bugfix.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22363>
_______________________________________


More information about the Python-bugs-list mailing list