diff --git a/Lib/argparse.py b/Lib/argparse.py index a32884db80d1ea..2059ec880c6a2d 100644 --- a/Lib/argparse.py +++ b/Lib/argparse.py @@ -2536,6 +2536,9 @@ def _get_values(self, action, arg_strings): elif action.nargs == SUPPRESS: value = SUPPRESS + elif len(arg_strings) == 0: + value = '--' + # all other types of nargs produce a list else: value = [self._get_value(action, v) for v in arg_strings] diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py index 7c1f5d36999a3d..295fda5dfba210 100644 --- a/Lib/test/test_argparse.py +++ b/Lib/test/test_argparse.py @@ -5405,6 +5405,12 @@ 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('--foo') + args = parser.parse_args(['--foo=--']) + self.assertEqual(NS(foo='--'), args) + # =========================== # parse_intermixed_args tests