From 61180446eee2aef07b042c7e8892c45afabd1499 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sun, 29 Sep 2024 10:52:07 +0300 Subject: gh-124345: Support abbreviated single-dash long options with = in argparse (GH-124428) --- Lib/argparse.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'Lib/argparse.py') diff --git a/Lib/argparse.py b/Lib/argparse.py index 3c2023e69e9..715d2ba3907 100644 --- a/Lib/argparse.py +++ b/Lib/argparse.py @@ -2319,7 +2319,9 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer): # but multiple character options always have to have their argument # separate elif option_string[0] in chars and option_string[1] not in chars: - option_prefix = option_string + option_prefix, sep, explicit_arg = option_string.partition('=') + if not sep: + sep = explicit_arg = None short_option_prefix = option_string[:2] short_explicit_arg = option_string[2:] @@ -2330,7 +2332,7 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer): result.append(tup) elif self.allow_abbrev and option_string.startswith(option_prefix): action = self._option_string_actions[option_string] - tup = action, option_string, None, None + tup = action, option_string, sep, explicit_arg result.append(tup) # shouldn't ever get here -- cgit v1.2.3