Skip to content

fix(time): catch OverflowError for non-finite floats (#333) - #373

Open
MeiSiristhebest wants to merge 2 commits into
python-humanize:mainfrom
MeiSiristhebest:fix/overflow-error-inf
Open

fix(time): catch OverflowError for non-finite floats (#333)#373
MeiSiristhebest wants to merge 2 commits into
python-humanize:mainfrom
MeiSiristhebest:fix/overflow-error-inf

Conversation

@MeiSiristhebest

Copy link
Copy Markdown

Description

Fixes #333 where naturaldelta(), naturaltime(), and precisedelta() raise an uncaught OverflowError when passed float('inf') or float('-inf').

Proposed Solution

Expand exception handling in _date_and_delta() and naturaldelta() from (ValueError, TypeError) to (ValueError, TypeError, OverflowError).

Testing Evidence

  • Added tests in tests/test_time.py covering float('inf') and float('-inf').
  • Full test suite passed (719 passed, 74 skipped, 0 failed).

@hugovk

hugovk commented Aug 2, 2026

Copy link
Copy Markdown
Member

Why is this better than the other 5 or so PRs opened for #333?

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.

naturaldelta() raises OverflowError on float('inf') instead of returning it unchanged

2 participants