summaryrefslogtreecommitdiffstats
path: root/Lib/argparse.py
diff options
context:
space:
mode:
authorJokimax <77680901+Jokimax@users.noreply.github.com>2024-02-02 22:13:00 (GMT)
committerGitHub <noreply@github.com>2024-02-02 22:13:00 (GMT)
commitc4a2e8a2c5188c3288d57b80852e92c83f46f6f3 (patch)
tree60f21e5ad2a17dcd8cad96c76e826c237eddc696 /Lib/argparse.py
parent73d20cafb54193c94577ca60df1ba0410b3ced74 (diff)
downloadcpython-c4a2e8a2c5188c3288d57b80852e92c83f46f6f3.zip
cpython-c4a2e8a2c5188c3288d57b80852e92c83f46f6f3.tar.gz
cpython-c4a2e8a2c5188c3288d57b80852e92c83f46f6f3.tar.bz2
gh-101599: argparse: simplify the option help string (GH-103372)
If the option with argument has short and long names, output argument only once, after the long name: -o, --option ARG description instead of -o ARG, --option ARG description
Diffstat (limited to 'Lib/argparse.py')
-rw-r--r--Lib/argparse.py10
1 files changed, 3 insertions, 7 deletions
diff --git a/Lib/argparse.py b/Lib/argparse.py
index a32884d..9e19f39 100644
--- a/Lib/argparse.py
+++ b/Lib/argparse.py
@@ -564,22 +564,18 @@ class HelpFormatter(object):
return metavar
else:
- parts = []
# if the Optional doesn't take a value, format is:
# -s, --long
if action.nargs == 0:
- parts.extend(action.option_strings)
+ return ', '.join(action.option_strings)
# if the Optional takes a value, format is:
- # -s ARGS, --long ARGS
+ # -s, --long ARGS
else:
default = self._get_default_metavar_for_optional(action)
args_string = self._format_args(action, default)
- for option_string in action.option_strings:
- parts.append('%s %s' % (option_string, args_string))
-
- return ', '.join(parts)
+ return ', '.join(action.option_strings) + ' ' + args_string
def _metavar_formatter(self, action, default_metavar):
if action.metavar is not None: