aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/Lib/argparse.py
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.com>2024-04-28 21:17:44 +0300
committershadchin <shadchin@yandex-team.com>2024-04-28 21:25:54 +0300
commita55d99a3eb72f90355bc146baeda18aa7eb97352 (patch)
treeb17cfed786effe8b81bba022239d6729f716fbeb /contrib/tools/python3/Lib/argparse.py
parent67bf49d08acf1277eff4c336021ac22d964bb4c4 (diff)
downloadydb-a55d99a3eb72f90355bc146baeda18aa7eb97352.tar.gz
Update Python 3 to 3.12.3
7d09de7d8b99ea2be554ef0fc61276942ca9c2e1
Diffstat (limited to 'contrib/tools/python3/Lib/argparse.py')
-rw-r--r--contrib/tools/python3/Lib/argparse.py62
1 files changed, 36 insertions, 26 deletions
diff --git a/contrib/tools/python3/Lib/argparse.py b/contrib/tools/python3/Lib/argparse.py
index 484a1efde43..120cb6c8458 100644
--- a/contrib/tools/python3/Lib/argparse.py
+++ b/contrib/tools/python3/Lib/argparse.py
@@ -225,7 +225,8 @@ class HelpFormatter(object):
# add the heading if the section was non-empty
if self.heading is not SUPPRESS and self.heading is not None:
current_indent = self.formatter._current_indent
- heading = '%*s%s:\n' % (current_indent, '', self.heading)
+ heading_text = _('%(heading)s:') % dict(heading=self.heading)
+ heading = '%*s%s\n' % (current_indent, '', heading_text)
else:
heading = ''
@@ -415,6 +416,8 @@ class HelpFormatter(object):
suppressed_actions_count += 1
exposed_actions_count = group_action_count - suppressed_actions_count
+ if not exposed_actions_count:
+ continue
if not group.required:
if start in inserts:
@@ -720,7 +723,7 @@ class ArgumentDefaultsHelpFormatter(HelpFormatter):
if action.default is not SUPPRESS:
defaulting_nargs = [OPTIONAL, ZERO_OR_MORE]
if action.option_strings or action.nargs in defaulting_nargs:
- help += ' (default: %(default)s)'
+ help += _(' (default: %(default)s)')
return help
@@ -1149,7 +1152,9 @@ class _VersionAction(Action):
version=None,
dest=SUPPRESS,
default=SUPPRESS,
- help="show program's version number and exit"):
+ help=None):
+ if help is None:
+ help = _("show program's version number and exit")
super(_VersionAction, self).__init__(
option_strings=option_strings,
dest=dest,
@@ -2004,7 +2009,7 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
# get the optional identified at this index
option_tuple = option_string_indices[start_index]
- action, option_string, explicit_arg = option_tuple
+ action, option_string, sep, explicit_arg = option_tuple
# identify additional optionals in the same arg string
# (e.g. -xyz is the same as -x -y -z if no args are required)
@@ -2031,18 +2036,27 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
and option_string[1] not in chars
and explicit_arg != ''
):
+ if sep or explicit_arg[0] in chars:
+ msg = _('ignored explicit argument %r')
+ raise ArgumentError(action, msg % explicit_arg)
action_tuples.append((action, [], option_string))
char = option_string[0]
option_string = char + explicit_arg[0]
- new_explicit_arg = explicit_arg[1:] or None
optionals_map = self._option_string_actions
if option_string in optionals_map:
action = optionals_map[option_string]
- explicit_arg = new_explicit_arg
+ explicit_arg = explicit_arg[1:]
+ if not explicit_arg:
+ sep = explicit_arg = None
+ elif explicit_arg[0] == '=':
+ sep = '='
+ explicit_arg = explicit_arg[1:]
+ else:
+ sep = ''
else:
- msg = _('ignored explicit argument %r')
- raise ArgumentError(action, msg % explicit_arg)
-
+ extras.append(char + explicit_arg)
+ stop = start_index + 1
+ break
# if the action expect exactly one argument, we've
# successfully matched the option; exit the loop
elif arg_count == 1:
@@ -2262,18 +2276,17 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
# if the option string is present in the parser, return the action
if arg_string in self._option_string_actions:
action = self._option_string_actions[arg_string]
- return action, arg_string, None
+ return action, arg_string, None, None
# if it's just a single character, it was meant to be positional
if len(arg_string) == 1:
return None
# if the option string before the "=" is present, return the action
- if '=' in arg_string:
- option_string, explicit_arg = arg_string.split('=', 1)
- if option_string in self._option_string_actions:
- action = self._option_string_actions[option_string]
- return action, option_string, explicit_arg
+ option_string, sep, explicit_arg = arg_string.partition('=')
+ if sep and option_string in self._option_string_actions:
+ action = self._option_string_actions[option_string]
+ return action, option_string, sep, explicit_arg
# search through all possible prefixes of the option string
# and all actions in the parser for possible interpretations
@@ -2282,7 +2295,7 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
# if multiple actions match, the option string was ambiguous
if len(option_tuples) > 1:
options = ', '.join([option_string
- for action, option_string, explicit_arg in option_tuples])
+ for action, option_string, sep, explicit_arg in option_tuples])
args = {'option': arg_string, 'matches': options}
msg = _('ambiguous option: %(option)s could match %(matches)s')
self.error(msg % args)
@@ -2306,7 +2319,7 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
# it was meant to be an optional but there is no such option
# in this parser (though it might be a valid option in a subparser)
- return None, arg_string, None
+ return None, arg_string, None, None
def _get_option_tuples(self, option_string):
result = []
@@ -2316,15 +2329,13 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
chars = self.prefix_chars
if option_string[0] in chars and option_string[1] in chars:
if self.allow_abbrev:
- if '=' in option_string:
- option_prefix, explicit_arg = option_string.split('=', 1)
- else:
- option_prefix = option_string
- explicit_arg = None
+ option_prefix, sep, explicit_arg = option_string.partition('=')
+ if not sep:
+ sep = explicit_arg = None
for option_string in self._option_string_actions:
if option_string.startswith(option_prefix):
action = self._option_string_actions[option_string]
- tup = action, option_string, explicit_arg
+ tup = action, option_string, sep, explicit_arg
result.append(tup)
# single character options can be concatenated with their arguments
@@ -2332,18 +2343,17 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
# separate
elif option_string[0] in chars and option_string[1] not in chars:
option_prefix = option_string
- explicit_arg = None
short_option_prefix = option_string[:2]
short_explicit_arg = option_string[2:]
for option_string in self._option_string_actions:
if option_string == short_option_prefix:
action = self._option_string_actions[option_string]
- tup = action, option_string, short_explicit_arg
+ tup = action, option_string, '', short_explicit_arg
result.append(tup)
elif option_string.startswith(option_prefix):
action = self._option_string_actions[option_string]
- tup = action, option_string, explicit_arg
+ tup = action, option_string, None, None
result.append(tup)
# shouldn't ever get here