GH-123945: Update regex for parsing negative numbers that contain underscores#123970
GH-123945: Update regex for parsing negative numbers that contain underscores#123970hauntsaninja merged 14 commits intopython:mainfrom
Conversation
Co-authored-by: Brandt Bucher <brandtbucher@gmail.com>
|
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.
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
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 <savannahostrowski@gmail.com> Co-authored-by: Brandt Bucher <brandtbucher@gmail.com> Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
|
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. |
|
|
||
| # 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.
It does not match -.5 which was matched by the old code.
…in underscores (python#123970) --------- Co-authored-by: Brandt Bucher <brandtbucher@gmail.com> Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
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.