Raise NumOutOfRangeError instead of IndexError for out-of-range 'teen' magnitudes - #257
Open
eeshsaxena wants to merge 1 commit into
Open
Raise NumOutOfRangeError instead of IndexError for out-of-range 'teen' magnitudes#257eeshsaxena wants to merge 1 commit into
eeshsaxena wants to merge 1 commit into
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
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.
Fixes #242.
number_to_words()is documented to raiseNumOutOfRangeErrorfor out-of-range inputs, andmillfn()enforces that:But
tenfn()'stens == 1(teen) branch indexedmill[mindex]directly, bypassing that check:So a number whose leading group is a teen — e.g.
10**40— leaked anIndexError: list index out of rangeinstead ofNumOutOfRangeError. Numbers whose leading group is not a teen (e.g.2 * 10**40) already raisedNumOutOfRangeErrorvia the other branch, so this makes the behaviour consistent.Repro (before)
After
The fix routes the teen branch through
millfn(). Added regression assertions totest_tenfnand atest_number_to_words_out_of_rangecovering10**36,10**40,10**100. Fulltest_pwd.py:172 passed, 16 xfailed.