diff --git a/Lib/argparse.py b/Lib/argparse.py index d4b6fb53af8..acd3154e681 100644 --- a/Lib/argparse.py +++ b/Lib/argparse.py @@ -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 diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py index 60a18b00806..f378606cdec 100644 --- a/Lib/test/test_argparse.py +++ b/Lib/test/test_argparse.py @@ -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, diff --git a/Misc/NEWS.d/next/Library/2020-07-06-15-25-29.bpo-22433.JBnwdX.rst b/Misc/NEWS.d/next/Library/2020-07-06-15-25-29.bpo-22433.JBnwdX.rst new file mode 100644 index 00000000000..aa0adb5a732 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-07-06-15-25-29.bpo-22433.JBnwdX.rst @@ -0,0 +1,2 @@ +Fixed handling of "--foo='bar baz'" as non-positional argument with +:mod:`argparse`.