Skip to content

Fix intcomma overflow for large Python integers - #392

Open
Yananix wants to merge 1 commit into
python-humanize:mainfrom
Yananix:fix/intcomma-large-integers
Open

Fix intcomma overflow for large Python integers#392
Yananix wants to merge 1 commit into
python-humanize:mainfrom
Yananix:fix/intcomma-large-integers

Conversation

@Yananix

@Yananix Yananix commented Sep 6, 2026

Copy link
Copy Markdown

Calling intcomma(10**400 + 123) with the default ndigits=None raises OverflowError because the non-finite check converts the integer to float. Python can format this integer directly with thousands separators, so the conversion imposes an unnecessary floating-point range limit.

Changes proposed in this pull request:

  • Skip the float validation for values that are already Python integers. Integers are finite, and the existing integer formatting path preserves all digits.
  • Add regression cases for positive and negative integers beyond the float range, checking the complete grouped output including the final 123.

Validation on Python 3.12:

  • Both regression cases fail with OverflowError before the fix and pass after it.
  • Compiled the translation catalogs with scripts/generate-translation-binaries.sh, then ran python -m pytest -q --benchmark-disable: 800 passed, no skips.
  • Ruff, Black, and git diff --check passed for the changed files.

This patch is scoped to integer inputs with default precision. It does not change numeric-string parsing or explicit decimal-place formatting.

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.

1 participant