[issue11874] argparse assertion failure with brackets in metavars

2014-09-09 Thread Zacrath

Changes by Zacrath mrdoom...@gmail.com:


--
nosy: +Zacrath

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11874
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22363] argparse AssertionError with add_mutually_exclusive_group and help=SUPPRESS

2014-09-09 Thread Zacrath

Zacrath added the comment:

I've confirmed that this is a duplicate of issue 17890.

In case anyone needs it, a workaround is to move the mutually exclusive group 
to the end of the arguments.

--

___
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



[issue22363] argparse AssertionError with add_mutually_exclusive_group and help=SUPPRESS

2014-09-08 Thread Zacrath

New submission from Zacrath:

Executing the attached script causes an AssertionError.

Traceback (most recent call last):
  File bug.py, line 18, in module
parser.format_usage()
  File /usr/lib/python3.4/argparse.py, line 2318, in format_usage
return formatter.format_help()
  File /usr/lib/python3.4/argparse.py, line 287, in format_help
help = self._root_section.format_help()
  File /usr/lib/python3.4/argparse.py, line 217, in format_help
func(*args)
  File /usr/lib/python3.4/argparse.py, line 338, in _format_usage
assert ' '.join(opt_parts) == opt_usage
AssertionError

The script was tested in a clean Python installation.

If any of the arguments are removed, there is no AssertionError exception.
If help=SUPPRESS is removed, there is no AssertionError exception.

This bug appears to have existed since Python 3.2, the first version that 
included argparse.

--
files: bug.py
messages: 226572
nosy: Zacrath, bethard
priority: normal
severity: normal
status: open
title: argparse AssertionError with add_mutually_exclusive_group and 
help=SUPPRESS
type: behavior
versions: Python 2.7, Python 3.1, Python 3.2, Python 3.3, Python 3.4, Python 3.5
Added file: http://bugs.python.org/file36572/bug.py

___
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



[issue22363] argparse AssertionError with add_mutually_exclusive_group and help=SUPPRESS

2014-09-08 Thread Zacrath

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