| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
…and naturaltime (#333)
for more information, see https://pre-commit.ci
|
Why is this better than the other 5 or so PRs opened for #333? |
Sorry, something went wrong.
|
Good point. #334 handles naturaldelta, but naturaltime and precisedelta also crash on inf because they go through _date_and_delta: >>> humanize.naturaltime(float("inf"))
OverflowError: cannot convert float infinity to integer
>>> humanize.precisedelta(float("inf"))
OverflowError: cannot convert float infinity to integerThis PR patches _date_and_delta so all three functions handle non-finite floats. You're right that catching OverflowError broadly was wrong — it suppressed exceptions for large finite floats like 1e30. I've updated this PR to match #334's check using math.isfinite(), restored the docstring, and added a test for the finite overflow behavior. If you'd prefer to fold the _date_and_delta fix into #334 instead, I'm also happy to close this one. |
Sorry, something went wrong.
|
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. naturaldelta(1e20) (finite, exceeds timedelta range): this PR raises, #375 returns "1e+20". Whichever semantics the maintainer prefers, one of the two should be closed as duplicate — flagging early since neither references the other. (Also noting for completeness that I reviewed #374 separately; unrelated.) |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
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