Thanks to visit codestin.com
Credit goes to github.com

Skip to content

GH-123945: Update regex for parsing negative numbers that contain underscores #123970

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update regex and add more test cases
  • Loading branch information
savannahostrowski committed Sep 12, 2024
commit 404b9b163e5699dfbae89d38f06ea8b413f6db1f
3 changes: 1 addition & 2 deletions Lib/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1360,8 +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+)?$')
# whether or not there are any optionals that look like negative
# numbers -- uses a list so it can be shared and edited
self._has_negative_number_optionals = []
Expand Down
4 changes: 3 additions & 1 deletion Lib/test/test_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1493,7 +1493,9 @@ class TestOptionLike(ParserTestCase):
failures = ['-x', '-y2.5', '-xa', '-x -a',
'-x -3', '-x -3.5', '-3 -3.5',
'-x -2.5', '-x -2.5 a', '-3 -.5',
'a x -1', '-x -1 a', '-3 -1 a']
'a x -1', '-x -1 a', '-3 -1 a',
'-x -_.45 -3 1_000', '-x -1_000.0_45 -3 1_000',
'-x -1__000_000.0 -3 1_000_000',]
successes = [
('', NS(x=None, y=None, z=[])),
('-x 2.5', NS(x=2.5, y=None, z=[])),
Expand Down
Loading