[3.12] gh-109475: Fix support of explicit option value "--" in argparse (GH-114814) (GH-115036)

For example "--option=--".
(cherry picked from commit 4aa4f0906d)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
Miss Islington (bot) 2024-02-05 22:02:00 +01:00 committed by GitHub
parent 21f06a22c0
commit 94ad68264c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 19 additions and 1 deletions

View file

@ -2488,7 +2488,7 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
# ========================
def _get_values(self, action, arg_strings):
# for everything but PARSER, REMAINDER args, strip out first '--'
if action.nargs not in [PARSER, REMAINDER]:
if not action.option_strings and action.nargs not in [PARSER, REMAINDER]:
try:
arg_strings.remove('--')
except ValueError: