Skip to content

Fix intcomma overflow for large Python integers - #392

Merged
hugovk merged 1 commit into
python-humanize:mainfrom
Yananix:fix/intcomma-large-integers
Sep 16, 2026
Merged

hugovk merged 1 commit into
python-humanize:mainfrom
Yananix:fix/intcomma-large-integers

Conversation

@Yananix

@Yananix Yananix commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

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.

@hugovk hugovk added the changelog: Fixed For any bug fixes label Sep 16, 2026
@codecov

codecov Bot commented Sep 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.57%. Comparing base (3201e70) to head (244ac0e).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #392   +/-   ##
=======================================
  Coverage   99.56%   99.57%           
=======================================
  Files          12       12           
  Lines         927      933    +6     
=======================================
+ Hits          923      929    +6     
  Misses          4        4           
Flag Coverage Δ
macos-latest 97.64% <100.00%> (+0.01%) ⬆️
ubuntu-latest 97.64% <100.00%> (+0.01%) ⬆️
windows-latest 95.49% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@hugovk
hugovk merged commit 984526c into python-humanize:main Sep 16, 2026
45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog: Fixed For any bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants