number_to_words leaks IndexError instead of NumOutOfRangeError for huge inputs
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.1k
- Forks
- 127
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
Found via an adversarial test pass on `inflect/__init__.py` against the main branch (version `7.5.1.dev33+g262a247d2`).
`engine().number_to_words(n)` is documented to raise `NumOutOfRangeError` for out-of-range inputs (the exception is imported and advertised). For numbers requiring magnitude index >= 12 (roughly 10^36 and above), instead of that documented exception, an uncaught `IndexError: list index out of range` leaks from `tenfn` at `inflect/__init__.py:3699`.
## Minimal repro
```python
import inflect
p = inflect.engine()
p.number_to_words(10**40)
# Expected: raises NumOutOfRangeError
# Actual: IndexError: list index out of range
# from tenfn -> mill[mindex] (inflect/__init__.py:3699)
```
Same failure mode at `10**36`, `10**40`, and `10**100` (all parametrized in my probe; all three exhibit the same IndexError).
## Why it matters
Library users who wrap calls in `try: ... except NumOutOfRangeError` (which is the documented contract) will not catch `IndexError`. Their code will crash unexpectedly when given a number above the supported range.
## Suggested fix
Either expand the `mill` table to cover larger magnitudes (probably impractical past a point), or guard `mill[mindex]` in `tenfn` with a magnitude-bounds check that raises `NumOutOfRangeError` when the magnitude would exceed `len(mill) - 1`.
Happy to send a PR if helpful. Thanks for the library.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in inflect/__init__.py at tenfn around line 3699, where mill[mindex] raises IndexError for the documented out-of-range inputs. Reproduce with 10**36, 10**40, and 10**100, then verify that each raises NumOutOfRangeError instead of IndexError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100