Title: Return non-finite floats unchanged from naturaldelta by eeshsaxena · Pull Request #343 · python-humanize/humanize · GitHub
Open Graph Title: Return non-finite floats unchanged from naturaldelta by eeshsaxena · Pull Request #343 · python-humanize/humanize
X Title: Return non-finite floats unchanged from naturaldelta by eeshsaxena · Pull Request #343 · python-humanize/humanize
Description: Summary Fixes #333. naturaldelta() documents that a value which cannot be converted to a number is "returned unchanged." float("nan") is handled (its int() raises ValueError, which is caught), but float("inf")/float("-inf") raise an uncaught OverflowError from int(value), because the except (ValueError, TypeError) clause omitted OverflowError. The behavior was asymmetric and contradicted the docstring. Before >>> humanize.naturaldelta(float("nan")) 'nan' >>> humanize.naturaldelta(float("inf")) OverflowError: cannot convert float infinity to integer After >>> humanize.naturaldelta(float("inf")) 'inf' >>> humanize.naturaldelta(float("-inf")) '-inf' Implementation note The catch is scoped to the int(value) guard only. A finite value too large to convert to a datetime.timedelta (e.g. 1e40) still raises OverflowError from timedelta(), as documented under Raises: - this is verified by an added test so the non-finite guard does not swallow the legitimate overflow. Tests Added test_naturaldelta_nonfinite (nan, inf, -inf returned unchanged) and test_naturaldelta_overflow (finite 1e40 still raises OverflowError). Full tests/test_time.py passes (387 passed).
Open Graph Description: Summary Fixes #333. naturaldelta() documents that a value which cannot be converted to a number is "returned unchanged." float("nan") is handled (its int() raises ValueError, wh...
X Description: Summary Fixes #333. naturaldelta() documents that a value which cannot be converted to a number is "returned unchanged." float("nan") is handled (its int() raise...
Opengraph URL: https://github.com/python-humanize/humanize/pull/343
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:a3fee8d9-157a-601c-16cf-45ec8ee3f142 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | DFDE:2D56BD:8DFCA:C2EB1:6A55328A |
| html-safe-nonce | f145d6af856f8580270b2134d9d2bb2b40368982523aab2087730fc7399de962 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERkRFOjJENTZCRDo4REZDQTpDMkVCMTo2QTU1MzI4QSIsInZpc2l0b3JfaWQiOiI0NDY4MjYyNDU4MTg0OTU2MjYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 6df6c6fd022909f3a10248e3b8ff5f7090bebe4140e0e43cb5011a7854906d20 |
| hovercard-subject-tag | pull_request:3990124089 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python-humanize/humanize/pull/343/files |
| twitter:image | https://avatars.githubusercontent.com/u/139802361?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/139802361?s=400&v=4 |
| og:image:alt | Summary Fixes #333. naturaldelta() documents that a value which cannot be converted to a number is "returned unchanged." float("nan") is handled (its int() raises ValueError, wh... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | fbd8fce4d63ac394c5405faa20aa50d5c9e56b979ac43ee1b26f8e7c47c4cd89 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/python-humanize/humanize git https://github.com/python-humanize/humanize.git |
| octolytics-dimension-user_id | 62149795 |
| octolytics-dimension-user_login | python-humanize |
| octolytics-dimension-repository_id | 466683324 |
| octolytics-dimension-repository_nwo | python-humanize/humanize |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 466683324 |
| octolytics-dimension-repository_network_root_nwo | python-humanize/humanize |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | cf96660b44878f418b09d3d6ecde00ad62332910 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width