Fix shadowed "тңг." currency symbol dropping its trailing dot - #80
Open
Sanjays2402 wants to merge 1 commit into
Open
Sanjays2402 wants to merge 1 commit into
Sanjays2402 wants to merge 1 commit into
Conversation
The dotted Kazakhstani tenge abbreviation "тңг." was listed *after* the
dot-less "тңг" in SAFE_CURRENCY_SYMBOLS. or_regex() builds an ordered
alternation, so the shorter "тңг" always matched first and the trailing
dot was silently dropped: Price.fromstring("1000 тңг.").currency was
"тңг" instead of "тңг.".
"тңг" was the only dotted/undotted national-abbreviation pair listed in
the wrong order; every sibling (руб., грн., лв.) already lists the dotted
form first so it wins the alternation. Swap the two entries to match that
convention, which also makes the previously unreachable "тңг." entry
effective.
Add a regression example to PRICE_PARSING_EXAMPLES_BUGS_CAUGHT covering
"1000 тңг." -> currency "тңг.".
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #80 +/- ##
=======================================
Coverage 98.23% 98.23%
=======================================
Files 3 3
Lines 113 113
Branches 16 16
=======================================
Hits 111 111
Misses 1 1
Partials 1 1
🚀 New features to boost your workflow:
|
AdrianAtZyte
approved these changes
Jul 3, 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.
Problem
Price.fromstring("1000 тңг.")returnscurrency="тңг"(Kazakhstani tengewithout its trailing dot) instead of
currency="тңг.", silently dropping theperiod that is part of the symbol as it appears in the text.
For comparison, the other dotted national abbreviations behave correctly:
currency(before)currency(after)1000 тңг.'тңг'❌'тңг.'✅1000 руб.'руб.''руб.'1000 грн.'грн.''грн.'1000 лв.'лв.''лв.'1000 тңг(no dot)'тңг''тңг'Root cause
SAFE_CURRENCY_SYMBOLSis turned into an ordered regex alternation byor_regex()("|".join(...)). In an ordered alternation the first matchingbranch wins, so when a shorter symbol is a prefix of a longer one and is listed
first, the longer one becomes unreachable.
"тңг"was listed before"тңг.":"тңг"is the only dotted/undotted pair in the wrong order. Every sibling(
руб./руб,грн./грн,лв./лв) already lists the dotted form first, sothose symbols keep their dot. The comment at the top of the list even notes that
longer variants "need to be before" shorter ones.
Fix
Swap the two entries so the dotted form comes first, matching the existing
convention for
руб.,грн., andлв.. This makes the previously dead"тңг."entry effective without affecting the dot-less"тңг"form.+2/−1 in
price_parser/parser.py(one swap), +4 in the test file.Testing
Added a regression example to
PRICE_PARSING_EXAMPLES_BUGS_CAUGHT(the list documented for "bugs we've found in a wild"):
Proof it guards the bug (source fix stashed, test kept):
Full suite after the fix: 1060 passed, 134 xfailed (was 1059 passed +
the 1 new case, no regressions).
ruff checkandruff format --checkareclean on both changed files.
This pull request was prepared with the assistance of AI, under my direction
and review.