Skip to content

Commit 6c2d203

Browse files
committed
fixup! bpo-22433: do not consider "--foo='bar baz'" to be a positional argument
1 parent b6a18bb commit 6c2d203

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

Lib/argparse.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2223,7 +2223,8 @@ def _parse_optional(self, arg_string):
22232223
if not self._has_negative_number_optionals:
22242224
return None
22252225

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

Lib/test/test_argparse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2022,7 +2022,7 @@ def test_parse_known_args(self):
20222022
self.parser.parse_known_args(['0.5', '--opt="with space"']),
20232023
(NS(foo=False, bar=0.5), ['--opt="with space"']),
20242024
)
2025-
self.assertRaisesRegexp(
2025+
self.assertRaisesRegex(
20262026
ArgumentParserError,
20272027
"invalid choice: '--opt with space'",
20282028
self.parser.parse_known_args,
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fixed handling of "--foo='bar baz'" as non-positional argument with
2+
:mod:`argparse`.

0 commit comments

Comments
 (0)