mirror of
https://github.com/python/cpython.git
synced 2025-08-27 12:16:04 +00:00
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>
This commit is contained in:
parent
7f3a4b967c
commit
e02cc6d42a
3 changed files with 7 additions and 2 deletions
|
@ -1997,7 +1997,11 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
|
||||||
# arguments, try to parse more single-dash options out
|
# arguments, try to parse more single-dash options out
|
||||||
# of the tail of the option string
|
# of the tail of the option string
|
||||||
chars = self.prefix_chars
|
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))
|
action_tuples.append((action, [], option_string))
|
||||||
char = option_string[0]
|
char = option_string[0]
|
||||||
option_string = char + explicit_arg[0]
|
option_string = char + explicit_arg[0]
|
||||||
|
|
|
@ -296,7 +296,7 @@ class TestOptionalsSingleDashCombined(ParserTestCase):
|
||||||
Sig('-z'),
|
Sig('-z'),
|
||||||
]
|
]
|
||||||
failures = ['a', '--foo', '-xa', '-x --foo', '-x -z', '-z -x',
|
failures = ['a', '--foo', '-xa', '-x --foo', '-x -z', '-z -x',
|
||||||
'-yx', '-yz a', '-yyyx', '-yyyza', '-xyza']
|
'-yx', '-yz a', '-yyyx', '-yyyza', '-xyza', '-x=']
|
||||||
successes = [
|
successes = [
|
||||||
('', NS(x=False, yyy=None, z=None)),
|
('', NS(x=False, yyy=None, z=None)),
|
||||||
('-x', NS(x=True, 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…
Add table
Add a link
Reference in a new issue