mirror of
https://github.com/python/cpython.git
synced 2025-09-09 10:21:43 +00:00
Fix for issue 9355 where with multiple mutually exclusive arguments, some brackets were being lost in the usage messages
This commit is contained in:
parent
1ca45a5292
commit
49998eec49
2 changed files with 27 additions and 2 deletions
|
@ -392,8 +392,14 @@ class HelpFormatter(object):
|
||||||
for action in group._group_actions:
|
for action in group._group_actions:
|
||||||
group_actions.add(action)
|
group_actions.add(action)
|
||||||
if not group.required:
|
if not group.required:
|
||||||
|
if start in inserts:
|
||||||
|
inserts[start] += ' ['
|
||||||
|
else:
|
||||||
inserts[start] = '['
|
inserts[start] = '['
|
||||||
inserts[end] = ']'
|
inserts[end] = ']'
|
||||||
|
else:
|
||||||
|
if start in inserts:
|
||||||
|
inserts[start] += ' ('
|
||||||
else:
|
else:
|
||||||
inserts[start] = '('
|
inserts[start] = '('
|
||||||
inserts[end] = ')'
|
inserts[end] = ')'
|
||||||
|
|
|
@ -2163,6 +2163,25 @@ class TestMutuallyExclusiveGroupErrors(TestCase):
|
||||||
raises(ValueError, add_argument, 'bar', nargs=1)
|
raises(ValueError, add_argument, 'bar', nargs=1)
|
||||||
raises(ValueError, add_argument, 'bar', nargs=argparse.PARSER)
|
raises(ValueError, add_argument, 'bar', nargs=argparse.PARSER)
|
||||||
|
|
||||||
|
def test_help(self):
|
||||||
|
parser = ErrorRaisingArgumentParser(prog='PROG')
|
||||||
|
group1 = parser.add_mutually_exclusive_group()
|
||||||
|
group1.add_argument('--foo', action='store_true')
|
||||||
|
group1.add_argument('--bar', action='store_false')
|
||||||
|
group2 = parser.add_mutually_exclusive_group()
|
||||||
|
group2.add_argument('--soup', action='store_true')
|
||||||
|
group2.add_argument('--nuts', action='store_false')
|
||||||
|
expected = '''\
|
||||||
|
usage: PROG [-h] [--foo | --bar] [--soup | --nuts]
|
||||||
|
|
||||||
|
optional arguments:
|
||||||
|
-h, --help show this help message and exit
|
||||||
|
--foo
|
||||||
|
--bar
|
||||||
|
--soup
|
||||||
|
--nuts
|
||||||
|
'''
|
||||||
|
self.assertEqual(parser.format_help(), textwrap.dedent(expected))
|
||||||
|
|
||||||
class MEMixin(object):
|
class MEMixin(object):
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue