diff options
author | steven.bethard <devnull@localhost> | 2009-07-26 15:16:18 +0000 |
---|---|---|
committer | steven.bethard <devnull@localhost> | 2009-07-26 15:16:18 +0000 |
commit | cffc1b330eb2293efba0b57bb0a3b56080283c75 (patch) | |
tree | e3b7ed63cb029324d5288676e0e5e3bf599c50c7 | |
parent | 25d79f58974cc14f475a4762926981e247c9f70c (diff) | |
download | argparse-cffc1b330eb2293efba0b57bb0a3b56080283c75.tar.gz |
Spaces now only signal a positional if the argument string doesn't start with an optional declared in the parser.
-rw-r--r-- | argparse.py | 8 | ||||
-rw-r--r-- | 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')),
]
|