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 <rep...@bugs.python.org>
<http://bugs.python.org/issue22363>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to