Treat integer-valued floats as their int in get_count - #258
Open
eeshsaxena wants to merge 2 commits into
Open
Conversation
tenfn() accessed mill[mindex] directly in the tens == 1 branch, bypassing the bounds check in millfn(). number_to_words() on numbers whose leading group is a teen (e.g. 10**40) therefore leaked an IndexError instead of the documented NumOutOfRangeError. Route the lookup through millfn(). Fixes jaraco#242
get_count(1.0) returned 2 instead of 1 because str(1.0) is "1.0",
which is not in pl_count_one. As a result plural("cat", 1.0) wrongly
produced "cats". Normalize integer-valued floats (e.g. 1.0 -> 1)
before the string comparison so they behave like their int
counterpart, while non-integer floats such as 1.5 still count as 2.
Fixes jaraco#232
Author
|
Hi! Gentle ping on this one; it's been open a couple of weeks. Happy to rebase or make any changes if anything's needed; whenever you get a chance to take a look, I'd really appreciate it. Thanks! |
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
get_count(1.0)returns2instead of1, soplural("cat", 1.0)incorrectly produces"cats".The root cause is that
get_countcomparesstr(count)againstpl_count_one. For a float like1.0,str(1.0)is"1.0", which is not inpl_count_one, so it falls through to the plural count of2.This normalizes integer-valued floats (e.g.
1.0->1) to their int form before the string comparison, so they behave like their int counterpart. Non-integer floats such as1.5still count as2, matching existing behavior.Before
After
Tests
Added
(1.0, 1),(2.0, 2),(1.5, 2)cases totest_countintests/test_pwd.py. Fulltests/test_pwd.pysuite passes (172 passed, 16 xfailed).Fixes #232