summaryrefslogtreecommitdiffstats
path: root/Lib/argparse.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2024-09-24 07:35:28 (GMT)
committerGitHub <noreply@github.com>2024-09-24 07:35:28 (GMT)
commitc578271366176a1d1b0941897efefb6e4d6508b4 (patch)
tree0cac631a9c1d775093fc705b47c4f814ec20d566 /Lib/argparse.py
parent3094cd17b0e5ba69309c54964744c797a70aa11b (diff)
downloadcpython-c578271366176a1d1b0941897efefb6e4d6508b4.zip
cpython-c578271366176a1d1b0941897efefb6e4d6508b4.tar.gz
cpython-c578271366176a1d1b0941897efefb6e4d6508b4.tar.bz2
gh-53780: Ignore the first "--" (double dash) between an option and command in argparse (GH-124275)
Diffstat (limited to 'Lib/argparse.py')
-rw-r--r--Lib/argparse.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/Lib/argparse.py b/Lib/argparse.py
index 7f6b31b..89496cb 100644
--- a/Lib/argparse.py
+++ b/Lib/argparse.py
@@ -2068,11 +2068,15 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
# and add the Positional and its args to the list
for action, arg_count in zip(positionals, arg_counts):
args = arg_strings[start_index: start_index + arg_count]
- # Strip out the first '--' if it is not in PARSER or REMAINDER arg.
- if (action.nargs not in [PARSER, REMAINDER]
- and arg_strings_pattern.find('-', start_index,
+ # Strip out the first '--' if it is not in REMAINDER arg.
+ if action.nargs == PARSER:
+ if arg_strings_pattern[start_index] == '-':
+ assert args[0] == '--'
+ args.remove('--')
+ elif action.nargs != REMAINDER:
+ if (arg_strings_pattern.find('-', start_index,
start_index + arg_count) >= 0):
- args.remove('--')
+ args.remove('--')
start_index += arg_count
if args and action.deprecated and action.dest not in warned:
self._warning(_("argument '%(argument_name)s' is deprecated") %