diff options
author | steven.bethard <devnull@localhost> | 2009-10-09 18:06:46 +0000 |
---|---|---|
committer | steven.bethard <devnull@localhost> | 2009-10-09 18:06:46 +0000 |
commit | 7fc9baae61b571e086e08b00e20cfa4377363cbc (patch) | |
tree | 6e41b3b3bd83df6b4aea574c2f7d33a9af797868 | |
parent | 7cc6c3f3317aebace4fe1e10dc926a9bf595c4f0 (diff) | |
download | argparse-7fc9baae61b571e086e08b00e20cfa4377363cbc.tar.gz |
Fix bug where options with a single letter were being considered as numbers.
-rw-r--r-- | argparse.py | 2 | ||||
-rw-r--r-- | test/test_argparse.py | 17 |
2 files changed, 18 insertions, 1 deletions
diff --git a/argparse.py b/argparse.py index 2ba966c..1ab2a53 100644 --- a/argparse.py +++ b/argparse.py @@ -1203,7 +1203,7 @@ class _ActionsContainer(object): self._defaults = {} # determines whether an "option" looks like a negative number - self._negative_number_matcher = _re.compile(r'^-\d+|-\d*.\d+$') + self._negative_number_matcher = _re.compile(r'^-\d+$|^-\d*\.\d+$') # whether or not there are any optionals that look like negative # numbers -- uses a list so it can be shared and edited diff --git a/test/test_argparse.py b/test/test_argparse.py index 8860592..0bd06ca 100644 --- a/test/test_argparse.py +++ b/test/test_argparse.py @@ -1121,6 +1121,23 @@ class TestOptionalsNumericAndPositionals(ParserTestCase): ] +class TestOptionalsAlmostNumericAndPositionals(ParserTestCase): + """Tests negative number args when almost numeric options are present""" + + argument_signatures = [ + Sig('x', nargs='?'), + Sig('-k4', dest='y', action='store_true'), + ] + failures = ['-k3'] + successes = [ + ('', NS(x=None, y=False)), + ('-2', NS(x='-2', y=False)), + ('a', NS(x='a', y=False)), + ('-k4', NS(x=None, y=True)), + ('-k4 a', NS(x='a', y=True)), + ] + + class TestEmptyAndSpaceContainingArguments(ParserTestCase): argument_signatures = [ |