mirror of https://github.com/python/cpython.git
gh-80448: argparse: Fix IndexError on store_true action (GH-15656)
(cherry picked from commit e02cc6d42a
)
Co-authored-by: Hai Shi <shihai1992@gmail.com>
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>
This commit is contained in:
parent
d75b2e2fc8
commit
92b531b858
|
@ -1997,7 +1997,11 @@ def consume_optional(start_index):
|
|||
# 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]
|
||||
|
|
|
@ -296,7 +296,7 @@ class TestOptionalsSingleDashCombined(ParserTestCase):
|
|||
Sig('-z'),
|
||||
]
|
||||
failures = ['a', '--foo', '-xa', '-x --foo', '-x -z', '-z -x',
|
||||
'-yx', '-yz a', '-yyyx', '-yyyza', '-xyza']
|
||||
'-yx', '-yz a', '-yyyx', '-yyyza', '-xyza', '-x=']
|
||||
successes = [
|
||||
('', NS(x=False, yyy=None, z=None)),
|
||||
('-x', NS(x=True, yyy=None, z=None)),
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Fix IndexError in :class:`argparse.ArgumentParser` when a ``store_true`` action is given an explicit argument.
|
Loading…
Reference in New Issue