diff options
author | rindeal <dev.rindeal@gmail.com> | 2024-10-14 06:36:53 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-14 09:36:53 +0300 |
commit | 66b3922b97388c328c9bd8df050eef11c0261fae (patch) | |
tree | a9056707e6f79127d6cae6e0208e58d7fdd249d7 /Lib/argparse.py | |
parent | cfc27bc50fe165330f2295f9ac0ad56ca5b0f31c (diff) | |
download | cpython-66b3922b97388c328c9bd8df050eef11c0261fae.tar.gz cpython-66b3922b97388c328c9bd8df050eef11c0261fae.zip |
gh-86357: argparse: use str() consistently and explicitly to print choices (GH-117766)
Signed-off-by: Jan Chren ~rindeal <dev.rindeal@gmail.com>
Diffstat (limited to 'Lib/argparse.py')
-rw-r--r-- | Lib/argparse.py | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/Lib/argparse.py b/Lib/argparse.py index 550415dc934..fa9f5211257 100644 --- a/Lib/argparse.py +++ b/Lib/argparse.py @@ -547,8 +547,7 @@ class HelpFormatter(object): if action.metavar is not None: result = action.metavar elif action.choices is not None: - choice_strs = [str(choice) for choice in action.choices] - result = '{%s}' % ','.join(choice_strs) + result = '{%s}' % ','.join(map(str, action.choices)) else: result = default_metavar @@ -599,8 +598,7 @@ class HelpFormatter(object): elif hasattr(value, '__name__'): params[name] = value.__name__ if params.get('choices') is not None: - choices_str = ', '.join([str(c) for c in params['choices']]) - params['choices'] = choices_str + params['choices'] = ', '.join(map(str, params['choices'])) return help_string % params def _iter_indented_subactions(self, action): @@ -717,7 +715,7 @@ def _get_action_name(argument): elif argument.dest not in (None, SUPPRESS): return argument.dest elif argument.choices: - return '{' + ','.join(argument.choices) + '}' + return '{%s}' % ','.join(map(str, argument.choices)) else: return None @@ -2607,8 +2605,8 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer): if isinstance(choices, str): choices = iter(choices) if value not in choices: - args = {'value': value, - 'choices': ', '.join(map(repr, action.choices))} + args = {'value': str(value), + 'choices': ', '.join(map(str, action.choices))} msg = _('invalid choice: %(value)r (choose from %(choices)s)') raise ArgumentError(action, msg % args) |