summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/argparse.py13
-rw-r--r--Lib/test/test_argparse.py22
2 files changed, 32 insertions, 3 deletions
diff --git a/Lib/argparse.py b/Lib/argparse.py
index fb042a8..736bf5a 100644
--- a/Lib/argparse.py
+++ b/Lib/argparse.py
@@ -400,10 +400,18 @@ class HelpFormatter(object):
except ValueError:
continue
else:
- end = start + len(group._group_actions)
+ group_action_count = len(group._group_actions)
+ end = start + group_action_count
if actions[start:end] == group._group_actions:
+
+ suppressed_actions_count = 0
for action in group._group_actions:
group_actions.add(action)
+ if action.help is SUPPRESS:
+ suppressed_actions_count += 1
+
+ exposed_actions_count = group_action_count - suppressed_actions_count
+
if not group.required:
if start in inserts:
inserts[start] += ' ['
@@ -413,7 +421,7 @@ class HelpFormatter(object):
inserts[end] += ']'
else:
inserts[end] = ']'
- else:
+ elif exposed_actions_count > 1:
if start in inserts:
inserts[start] += ' ('
else:
@@ -487,7 +495,6 @@ class HelpFormatter(object):
text = _re.sub(r'(%s) ' % open, r'\1', text)
text = _re.sub(r' (%s)' % close, r'\1', text)
text = _re.sub(r'%s *%s' % (open, close), r'', text)
- text = _re.sub(r'\(([^|]*)\)', r'\1', text)
text = text.strip()
# return the text
diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py
index 4d43e33..5df6f32 100644
--- a/Lib/test/test_argparse.py
+++ b/Lib/test/test_argparse.py
@@ -3729,6 +3729,28 @@ class TestHelpUsage(HelpTestCase):
version = ''
+class TestHelpUsageWithParentheses(HelpTestCase):
+ parser_signature = Sig(prog='PROG')
+ argument_signatures = [
+ Sig('positional', metavar='(example) positional'),
+ Sig('-p', '--optional', metavar='{1 (option A), 2 (option B)}'),
+ ]
+
+ usage = '''\
+ usage: PROG [-h] [-p {1 (option A), 2 (option B)}] (example) positional
+ '''
+ help = usage + '''\
+
+ positional arguments:
+ (example) positional
+
+ options:
+ -h, --help show this help message and exit
+ -p {1 (option A), 2 (option B)}, --optional {1 (option A), 2 (option B)}
+ '''
+ version = ''
+
+
class TestHelpOnlyUserGroups(HelpTestCase):
"""Test basic usage messages"""