mirror of
https://github.com/python/cpython.git
synced 2025-08-25 03:04:55 +00:00
gh-81691: Fix handling of multiple "--" (double dashes) in argparse (GH-124233)
Only the first one has now been removed, all subsequent ones are now taken literally.
This commit is contained in:
parent
7a2d77c903
commit
aae126748f
3 changed files with 67 additions and 8 deletions
|
@ -2070,6 +2070,11 @@ 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,
|
||||
start_index + arg_count) >= 0):
|
||||
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") %
|
||||
|
@ -2470,13 +2475,6 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
|
|||
# Value conversion methods
|
||||
# ========================
|
||||
def _get_values(self, action, arg_strings):
|
||||
# for everything but PARSER, REMAINDER args, strip out first '--'
|
||||
if not action.option_strings and action.nargs not in [PARSER, REMAINDER]:
|
||||
try:
|
||||
arg_strings.remove('--')
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
# optional argument produces a default when not present
|
||||
if not arg_strings and action.nargs == OPTIONAL:
|
||||
if action.option_strings:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue