Skip to content

Keep whole numbers finite when they do not fit in a float - #452

Open
ShamikOfficial wants to merge 2 commits into
python-humanize:mainfrom
ShamikOfficial:fix-large-int-nonfinite-419
Open

ShamikOfficial wants to merge 2 commits into
python-humanize:mainfrom
ShamikOfficial:fix-large-int-nonfinite-419

Conversation

@ShamikOfficial

Copy link
Copy Markdown

Fixes #419

float() was used to test for NaN and infinity. For an integer larger than the float range that raises OverflowError. For the same number written as a digit string, float() returns infinity, so the value was reported as +Inf.

Whole numbers are now treated as finite. Scientific notation for integers that do not fit in a float is formatted with Decimal, so it does not overflow.

Tested with pytest tests/test_number.py (242 passed).

ShamikOfficial and others added 2 commits October 11, 2026 17:52
float() raised OverflowError for large ints and reported the same digit string as infinity.

Co-authored-by: Cursor <cursoragent@cursor.com>
@ShamikOfficial

Copy link
Copy Markdown
Author

I don't have permission to add labels. Please add changelog: Fixed when you have a moment so the changelog check can pass.

@Wkhanex Wkhanex left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The huge integer and decimal-string controls pass, but this head defines _nonfinite_float twice with identical bodies. I confirmed two top-level definitions in the AST of src/humanize/number.py; Python silently overwrites the first definition with the second. Please remove the duplicate before merging so there is one implementation to maintain and no redefinition lint finding. I also executed scientific/apnumber controls for 10**400 and its decimal string; both remained finite and exact. AI-assisted review on Python 3.12 with English locale hooks, not the full package suite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Several number functions raise OverflowError on integers larger than a float

2 participants