Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions Lib/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -2223,8 +2223,8 @@ def _parse_optional(self, arg_string):
if not self._has_negative_number_optionals:
return None

# if it contains a space, it was meant to be a positional
if ' ' in arg_string:
# if it contains a space (before any equal sign), it was meant to be a positional
if ' ' in arg_string.split("=", 1)[0]:
return None

# it was meant to be an optional but there is no such option
Expand Down
9 changes: 9 additions & 0 deletions Lib/test/test_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -2018,6 +2018,15 @@ def test_parse_known_args(self):
self.parser.parse_known_args('0.5 -W 1 b -X Y -w 7 Z'.split()),
(NS(foo=False, bar=0.5, w=7, x='b'), ['-W', '-X', 'Y', 'Z']),
)
self.assertEqual(
self.parser.parse_known_args(['0.5', '--opt="with space"']),
(NS(foo=False, bar=0.5), ['--opt="with space"']),
)
self.assertRaisesRegexp(
ArgumentParserError,
"invalid choice: '--opt with space'",
self.parser.parse_known_args,
['0.5', '--opt with space'])

def test_dest(self):
parser = ErrorRaisingArgumentParser()
Expand Down