Honor digit_group_separator's complementary decimal separator - #77
Open
binggao1230 wants to merge 3 commits into
Open
binggao1230 wants to merge 3 commits into
binggao1230 wants to merge 3 commits into
Conversation
Price.fromstring documents that passing digit_group_separator="," parses "1.000" as 1 (the "." being the decimal separator), and symmetrically for ".". It stripped the group separator but left decimal_separator as None, so parse_number re-guessed the remaining "." or "," and produced the wrong amount (e.g. "1.000" -> 1000). When the caller declares one of "."/"," as the digit group separator and passes no explicit decimal_separator, treat the other symbol as the decimal separator, matching the documented behaviour. Other separators (e.g. space) and the explicit decimal_separator path are unaffected.
Comment on lines
+62
to
+63
| # The remaining "." or "," must be the decimal separator, since the | ||
| # caller declared the other symbol to be the digit group separator. |
Contributor
There was a problem hiding this comment.
Could you remove this comment and instead update the docstring to reflect the new logic?
Member
There was a problem hiding this comment.
(That they won't is the main reason I close such PRs)
Author
There was a problem hiding this comment.
Done — comment dropped, docstring now covers the inference. Sorry for the long delay.
AdrianAtZyte
approved these changes
Jun 23, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #77 +/- ##
===========================================
+ Coverage 98.23% 100.00% +1.76%
===========================================
Files 3 3
Lines 113 115 +2
Branches 16 17 +1
===========================================
+ Hits 111 115 +4
+ Misses 1 0 -1
+ Partials 1 0 -1
🚀 New features to boost your workflow:
|
Contributor
|
Do you think you could complete test coverage based on the feedback from CodeCov? |
Author
|
Added a test for the explicit-decimal-separator case (1e6e740) — the group-separator inference now has full branch coverage (patch 100%). |
AdrianAtZyte
approved these changes
Jul 31, 2026
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.
Summary
Price.fromstringdocuments thatdigit_group_separatorimplies the complementary decimal separator:The
","case is broken:fromstringstrips the group separator but leavesdecimal_separator=None, soparse_numberre-guesses the remaining./,— and for"1.000"it guesses the.is a thousands group. The sibling paths confirm the inconsistency:decimal_separator="."on the same input correctly givesDecimal('1.000'), anddigit_group_separator="."correctly gives1000— only the","-group branch was wrong.Fix
When the caller declares one of
"."/","as the digit group separator and passes no explicitdecimal_separator, treat the other symbol as the decimal separator — exactly the documented semantics:Non-
./,group separators (e.g. a space) and the explicit-decimal_separatorpath are unaffected.Verification
master(64e213a): all four docstring claims now hold, and mixed inputs like"1,000.50"(group=","→1000.50) and"1.000,50"(group="."→1000.50) parse correctly.test_price_digit_group_separatormirroringtest_price_decimal_separator; the documented","-group case fails before the fix and passes after.ruffandmypyclean.This pull request was prepared with the assistance of AI, under my direction and review.