-
-
Notifications
You must be signed in to change notification settings - Fork 32k
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
Conversation
Co-authored-by: Brandt Bucher <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I'm not sure the tests are testing the right scenario. Unless I'm mistaken, I think they pass without the change.
Whoops, that's my bad. I should have tested without the fix as well. I've updated the tests and verified that they do fail without the regex update. I wasn't sure where to put these new tests, so please let me know if there's a better way to do this or a better spot to place them. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the quick update!
Don't have strong opinions on the location of the test, but it is a little weird that only two of the preexisting methods in TestParseKnownArgs
test parse_known_args
🤷 The most similar test cases seem to be earlier in the file and use the ParserTestCase
infra
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Misc/NEWS.d/next/Library/2024-09-11-19-05-32.gh-issue-123945.jLwybB.rst
Outdated
Show resolved
Hide resolved
Thanks @savannahostrowski for the PR, and @hauntsaninja for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13. |
…in underscores (pythonGH-123970) --------- (cherry picked from commit 14e5bdc) Co-authored-by: Savannah Ostrowski <[email protected]> Co-authored-by: Brandt Bucher <[email protected]> Co-authored-by: Shantanu <[email protected]>
Sorry, @savannahostrowski and @hauntsaninja, I could not cleanly backport this to
|
GH-124158 is a backport of this pull request to the 3.13 branch. |
GH-124175 is a backport of this pull request to the 3.12 branch. |
@@ -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+$') | |||
self._negative_number_matcher = _re.compile(r'^-\d[\d_]*(\.\d[\d_]*)?$') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not match -.5
which was matched by the old code.
…in underscores (python#123970) --------- Co-authored-by: Brandt Bucher <[email protected]> Co-authored-by: Shantanu <[email protected]>
This PR updates the regex for parsing numbers with argparse to account for negative numbers with underscores. I've also added some test cases to account for negative ints and floats, and numbers that may contain multiple underscores. This behaviour repros on versions as old as 3.9, possibly earlier.