fixup! bpo-22433: do not consider "--foo='bar baz'" to be a positional argument

This commit is contained in:
Daniel Hahler 2020-07-06 15:25:47 +02:00
parent b6a18bb212
commit 6c2d2033f0
3 changed files with 5 additions and 2 deletions

View File

@ -2223,7 +2223,8 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
if not self._has_negative_number_optionals:
return None
# if it contains a space (before any equal sign), it was meant to be a positional
# 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

View File

@ -2022,7 +2022,7 @@ class TestAddSubparsers(TestCase):
self.parser.parse_known_args(['0.5', '--opt="with space"']),
(NS(foo=False, bar=0.5), ['--opt="with space"']),
)
self.assertRaisesRegexp(
self.assertRaisesRegex(
ArgumentParserError,
"invalid choice: '--opt with space'",
self.parser.parse_known_args,

View File

@ -0,0 +1,2 @@
Fixed handling of "--foo='bar baz'" as non-positional argument with
:mod:`argparse`.