summaryrefslogtreecommitdiffstats
path: root/Lib/argparse.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-03-05 15:16:14 (GMT)
committerGitHub <noreply@github.com>2023-03-05 15:16:14 (GMT)
commit2a062f275970b3775b055c2c82f31b766271ae18 (patch)
treeb979dcc7adbe32657e2a6b90c376869eaaf03719 /Lib/argparse.py
parentd4a04e55d8bd8eaa307f3e4aa8b443301a0d996a (diff)
downloadcpython-2a062f275970b3775b055c2c82f31b766271ae18.zip
cpython-2a062f275970b3775b055c2c82f31b766271ae18.tar.gz
cpython-2a062f275970b3775b055c2c82f31b766271ae18.tar.bz2
gh-101979: argparse: fix a bug where parentheses in metavar argument of add_argument() were dropped (GH-102318)
(cherry picked from commit 9a478be1a4314734c697dda7a7b0e633a6fb0751) Co-authored-by: Yeojin Kim <yeojin.dev@gmail.com>
Diffstat (limited to 'Lib/argparse.py')
-rw-r--r--Lib/argparse.py13
1 files changed, 10 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