From bb13946848be05fd978072ca0a44c798b9906a3f Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Sun, 22 Sep 2024 14:55:52 -0700 Subject: [PATCH 1/3] Add another test case for -.5 --- Lib/argparse.py | 2 +- Lib/test/test_argparse.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/argparse.py b/Lib/argparse.py index 7988c447d03584..e14c4c7103ddb1 100644 --- a/Lib/argparse.py +++ b/Lib/argparse.py @@ -1360,7 +1360,7 @@ def __init__(self, self._defaults = {} # determines whether an "option" looks like a negative number - self._negative_number_matcher = _re.compile(r'^-\d[\d_]*(\.\d[\d_]*)?$') + self._negative_number_matcher = _re.compile(r'^-(\d+(_\d+)*(\.\d+(_\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/Lib/test/test_argparse.py b/Lib/test/test_argparse.py index 138ff19e86acf4..d7f04fa95433b1 100644 --- a/Lib/test/test_argparse.py +++ b/Lib/test/test_argparse.py @@ -2111,6 +2111,7 @@ class TestNegativeNumber(ParserTestCase): ('--int -1_000_000 --float -1_000_000.0', NS(int=-1000000, float=-1000000.0)), ('--float -1_000.0', NS(int=None, float=-1000.0)), ('--float -1_000_000.0_0', NS(int=None, float=-1000000.0)), + ('--float -.5', NS(int=None, float=-0.5)), ] class TestInvalidAction(TestCase): From 91db79473967d0a95790fe6a4f0934ccc36914a7 Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Mon, 23 Sep 2024 10:38:31 -0700 Subject: [PATCH 2/3] Update Lib/argparse.py Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> --- Lib/argparse.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/argparse.py b/Lib/argparse.py index e14c4c7103ddb1..b77da29417b920 100644 --- a/Lib/argparse.py +++ b/Lib/argparse.py @@ -1360,7 +1360,7 @@ def __init__(self, self._defaults = {} # determines whether an "option" looks like a negative number - self._negative_number_matcher = _re.compile(r'^-(\d+(_\d+)*(\.\d+(_\d+)*)?|\.\d+(_\d+)*)$') + self._negative_number_matcher = _re.compile(r'^-(?:\d+(?:_\d+)*(?:\.\d+(?:_\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 From 1c24113ad68de4d7425c575c67933716c5b6c8ce Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Mon, 23 Sep 2024 10:38:53 -0700 Subject: [PATCH 3/3] Update Lib/test/test_argparse.py Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> --- Lib/test/test_argparse.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py index d7f04fa95433b1..37d07968b22543 100644 --- a/Lib/test/test_argparse.py +++ b/Lib/test/test_argparse.py @@ -2112,6 +2112,7 @@ class TestNegativeNumber(ParserTestCase): ('--float -1_000.0', NS(int=None, float=-1000.0)), ('--float -1_000_000.0_0', NS(int=None, float=-1000000.0)), ('--float -.5', NS(int=None, float=-0.5)), + ('--float -.5_000', NS(int=None, float=-0.5)), ] class TestInvalidAction(TestCase):