diff options
-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 = [ |