summaryrefslogtreecommitdiffstats
path: root/Lib/argparse.py
diff options
context:
space:
mode:
authorHai Shi <shihai1992@gmail.com>2022-11-12 01:51:38 (GMT)
committerGitHub <noreply@github.com>2022-11-12 01:51:38 (GMT)
commite02cc6d42aee1f0a9ee629f76576eee478224d9d (patch)
tree875e7b8c34c520747b940c01226216d581caf518 /Lib/argparse.py
parent7f3a4b967cfb1596a3fda6c34f900f8586b16700 (diff)
downloadcpython-e02cc6d42aee1f0a9ee629f76576eee478224d9d.zip
cpython-e02cc6d42aee1f0a9ee629f76576eee478224d9d.tar.gz
cpython-e02cc6d42aee1f0a9ee629f76576eee478224d9d.tar.bz2
gh-80448: argparse: Fix IndexError on store_true action (#15656)
Co-authored-by: RĂ©mi Lapeyre <remi.lapeyre@henki.fr> Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com> Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
Diffstat (limited to 'Lib/argparse.py')
-rw-r--r--Lib/argparse.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/Lib/argparse.py b/Lib/argparse.py
index d2dcfdf..240625f 100644
--- a/Lib/argparse.py
+++ b/Lib/argparse.py
@@ -1997,7 +1997,11 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
# arguments, try to parse more single-dash options out
# of the tail of the option string
chars = self.prefix_chars
- if arg_count == 0 and option_string[1] not in chars:
+ if (
+ arg_count == 0
+ and option_string[1] not in chars
+ and explicit_arg != ''
+ ):
action_tuples.append((action, [], option_string))
char = option_string[0]
option_string = char + explicit_arg[0]