Allow alternative space characters as group separator when parsing numbers#1007
Merged
akx merged 2 commits intopython-babel:masterfrom Apr 22, 2024
Merged
Conversation
akx
requested changes
Jun 27, 2023
Member
akx
left a comment
There was a problem hiding this comment.
Thanks for the contribution! Some perf-related comments within.
cab7135 to
7fc29f6
Compare
Member
|
@ronnix Sorry for dropping the ball on my part here... Could you rebase this? :) |
7fc29f6 to
b213b51
Compare
Contributor
Author
|
@akx done! |
…mbers The French group separator is `"\u202f"` (narrow non-breaking space), but when parsing numbers in the real world, you will most often encounter either a regular space character (`" "`) or a non-breaking space character (`"\xa0"`). The issue was partially adressed earlier in python-babel#637, but only to allow regular spaces instead of non-breaking spaces `"\xa0"` in `parse_decimal`. This commit goes further by changing both `parse_number` and `parse_decimal` to allow any other space character (using the `\s` character class of regular expressions) when the group character is itself a space character, but is not present in the string to parse. Unit tests are included.
… as group symbols The `\s` character class (or the `string.isspace()` method) could match characters like new lines that we probably don’t want to consider as potential group symbols in numbers.
b213b51 to
181d701
Compare
Contributor
Author
|
@akx I fixed the linter error |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1007 +/- ##
==========================================
- Coverage 90.99% 90.69% -0.31%
==========================================
Files 26 26
Lines 4444 4449 +5
==========================================
- Hits 4044 4035 -9
- Misses 400 414 +14 ☔ View full report in Codecov by Sentry. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
The French group separator is
"\u202f"(narrow non-breaking space), but when parsing numbers in the real world, you will most often encounter either a regular space character (" ") or a non-breaking space character ("\xa0").The issue was partially adressed earlier in #637, but only to allow regular spaces instead of non-breaking spaces
"\xa0"inparse_decimal.Contents
This PR goes further by changing both
parse_numberandparse_decimalto allowany other space character (using theany of those 3 space characters when the expected group symbol is itself one such space character, but is not present in the string to parse.\scharacter class of regular expressions)Unit tests are included.