fix(time): catch OverflowError for non-finite floats (#333) - #373
fix(time): catch OverflowError for non-finite floats (#333)#373MeiSiristhebest wants to merge 4 commits into
Conversation
for more information, see https://pre-commit.ci
|
Why is this better than the other 5 or so PRs opened for #333? |
|
Good point. #334 handles >>> humanize.naturaltime(float("inf"))
OverflowError: cannot convert float infinity to integer
>>> humanize.precisedelta(float("inf"))
OverflowError: cannot convert float infinity to integerThis PR patches You're right that catching If you'd prefer to fold the |
|
Heads-up for maintainers: this PR and #375 fix the same OverflowError-on-non-finite issue (#333) but with opposite semantics for finite too-large values:
These will behave differently for e.g. (Also noting for completeness that I reviewed #374 separately; unrelated.) |
Description
Fixes #333 where
naturaldelta(),naturaltime(), andprecisedelta()raise an uncaughtOverflowErrorwhen passedfloat('inf')orfloat('-inf').Proposed Solution
Expand exception handling in
_date_and_delta()andnaturaldelta()from(ValueError, TypeError)to(ValueError, TypeError, OverflowError).Testing Evidence
tests/test_time.pycoveringfloat('inf')andfloat('-inf').