Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -2488,7 +2488,7 @@ def parse_known_intermixed_args(self, args=None, namespace=None):
# ========================
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:
Expand Down
16 changes: 16 additions & 0 deletions Lib/test/test_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -5332,6 +5332,22 @@ def test_zero_or_more_optional(self):
args = parser.parse_args([])
self.assertEqual(NS(x=[]), args)

def test_double_dash(self):
parser = argparse.ArgumentParser()
parser.add_argument('-f', '--foo', nargs='*')
parser.add_argument('bar', nargs='*')

args = parser.parse_args(['--foo=--'])
self.assertEqual(NS(foo=['--'], bar=[]), args)
args = parser.parse_args(['--foo', '--'])
self.assertEqual(NS(foo=[], bar=[]), args)
args = parser.parse_args(['-f--'])
self.assertEqual(NS(foo=['--'], bar=[]), args)
args = parser.parse_args(['-f', '--'])
self.assertEqual(NS(foo=[], bar=[]), args)
args = parser.parse_args(['--foo', 'a', 'b', '--', 'c', 'd'])
self.assertEqual(NS(foo=['a', 'b'], bar=['c', 'd']), args)


# ===========================
# parse_intermixed_args tests
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix support of explicit option value "--" in :mod:`argparse` (e.g.
``--option=--``).