From cffc1b330eb2293efba0b57bb0a3b56080283c75 Mon Sep 17 00:00:00 2001 From: "steven.bethard" Date: Sun, 26 Jul 2009 15:16:18 +0000 Subject: Spaces now only signal a positional if the argument string doesn't start with an optional declared in the parser. --- argparse.py | 8 ++++---- test/test_argparse.py | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/argparse.py b/argparse.py index bf3f277..05dbffb 100644 --- a/argparse.py +++ b/argparse.py @@ -1937,10 +1937,6 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer): if not arg_string: return None - # if it contains a space, it was meant to be a positional - if ' ' in arg_string: - return None - # if it doesn't start with a prefix, it was meant to be positional if not arg_string[0] in self.prefix_chars: return None @@ -1978,6 +1974,10 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer): 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: + return None + # it was meant to be an optional but there is no such option # in this parser (though it might be a valid option in a subparser) return None, arg_string, None diff --git a/test/test_argparse.py b/test/test_argparse.py index 011b9b6..452933f 100644 --- a/test/test_argparse.py +++ b/test/test_argparse.py @@ -1117,7 +1117,7 @@ class TestEmptyAndSpaceContainingArguments(ParserTestCase): argument_signatures = [ Sig('x', nargs='?'), - Sig('-y'), + Sig('-y', '--yyy', dest='y'), ] failures = ['-y'] successes = [ @@ -1127,6 +1127,8 @@ class TestEmptyAndSpaceContainingArguments(ParserTestCase): (['-y', ''], NS(x=None, y='')), (['-y', 'a badger'], NS(x=None, y='a badger')), (['-y', '-a badger'], NS(x=None, y='-a badger')), + (['--yyy=a badger'], NS(x=None, y='a badger')), + (['--yyy=-a badger'], NS(x=None, y='-a badger')), ] -- cgit v1.2.1