Title: Inconsistencies between documentation/annotations and behavior · Issue #28 · python-humanize/humanize · GitHub
Open Graph Title: Inconsistencies between documentation/annotations and behavior · Issue #28 · python-humanize/humanize
X Title: Inconsistencies between documentation/annotations and behavior · Issue #28 · python-humanize/humanize
Description: naturaltime() supports timedelta. It is not documented, but humanize.naturaltime() accepts timedelta. I used it for years until type annotations were added, and MyPy started to complain. timedelta is still accepted at runtime. >>> import...
Open Graph Description: naturaltime() supports timedelta. It is not documented, but humanize.naturaltime() accepts timedelta. I used it for years until type annotations were added, and MyPy started to complain. timedelta ...
X Description: naturaltime() supports timedelta. It is not documented, but humanize.naturaltime() accepts timedelta. I used it for years until type annotations were added, and MyPy started to complain. timedelta ...
Opengraph URL: https://github.com/python-humanize/humanize/issues/28
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Inconsistencies between documentation/annotations and behavior","articleBody":"## `naturaltime()` supports `timedelta`.\r\n\r\nIt is not documented, but `humanize.naturaltime()` accepts `timedelta`. I used it for years until type annotations were added, and MyPy started to complain. `timedelta` is still accepted at runtime.\r\n\r\n```pycon\r\n\u003e\u003e\u003e import datetime, humanize\r\n\u003e\u003e\u003e humanize.naturaltime(datetime.timedelta(days=5, hours=3))\r\n'5 days ago'\r\n\u003e\u003e\u003e humanize.naturaltime(datetime.timedelta(hours=123))\r\n'5 days ago'\r\n```\r\n\r\nI expect one of two things:\r\n\r\n1. Document that `humanize.naturaltime()` accepts `timedelta`, not only `datetime | int` and update type annotation.\r\n2. Make `humanize.naturaltime()` rejecting `timedelta` (of course, after some deprecation period).\r\n\r\nOption 1 is more compatible, but option 2 looks more logical.\r\n\r\n## `naturaltime()` and `naturaldelta()` accept not only `int`, but `float` too.\r\n\r\n```pycon\r\n\u003e\u003e\u003e humanize.naturaltime(23.5)\r\n'23 seconds ago'\r\n\u003e\u003e\u003e humanize.naturaldelta(23.5)\r\n'23 seconds'\r\n```\r\n\r\nIt is expected, since timestamp in Python is `float`, but it should be documented, and annotations should be updated.\r\n\r\n## `naturaltime()`, `naturaldelta()` , `naturaldate()` and `naturalday()` accept arbitrary object without error.\r\n\r\n```pycon\r\n\u003e\u003e\u003e humanize.naturaltime([1, 2, 3])\r\n'[1, 2, 3]'\r\n\u003e\u003e\u003e humanize.naturaldelta([1, 2, 3])\r\n'[1, 2, 3]'\r\n\u003e\u003e\u003e humanize.naturaldate([1, 2, 3])\r\n'[1, 2, 3]'\r\n\u003e\u003e\u003e humanize.naturalday([1, 2, 3])\r\n'[1, 2, 3]'\r\n```\r\n\r\nIt is unsafe, because allows programming errors to slip unnoticed. `humanize.naturalsize()` raises an error, as expected.\r\n\r\nHumanize 4.2.1\r\n","author":{"url":"https://github.com/serhiy-storchaka","@type":"Person","name":"serhiy-storchaka"},"datePublished":"2022-06-24T16:49:29.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":9},"url":"https://github.com/28/humanize/issues/28"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:eee5198c-d172-50d0-7d4f-ebf185e0b8ce |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D286:DD10E:61F3:8469:6A558346 |
| html-safe-nonce | a71713bd5f117dc471e5159dc0676c3d288b484b1f69aa2e58a872425f04a9ff |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMjg2OkREMTBFOjYxRjM6ODQ2OTo2QTU1ODM0NiIsInZpc2l0b3JfaWQiOiIxNzc4MzgzMzM4NzEwODYwNjE0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | f72297f395f21fa197d2ca6cc07853008c63ffdebb97efce401e0d62bf27a9ea |
| hovercard-subject-tag | issue:1283965745 |
| github-keyboard-shortcuts | repository,issues,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/_view_fragments/issues/show/python-humanize/humanize/28/issue_layout |
| twitter:image | https://opengraph.githubassets.com/108309bd4dc6a2c7c41a1a85fc34610451d74026227a7ce3d0a9be9a291595a7/python-humanize/humanize/issues/28 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/108309bd4dc6a2c7c41a1a85fc34610451d74026227a7ce3d0a9be9a291595a7/python-humanize/humanize/issues/28 |
| og:image:alt | naturaltime() supports timedelta. It is not documented, but humanize.naturaltime() accepts timedelta. I used it for years until type annotations were added, and MyPy started to complain. timedelta ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | serhiy-storchaka |
| hostname | github.com |
| expected-hostname | github.com |
| None | b5665c84831ed9ac4fb79519c16c9c5580ba8092fb8bb6e3e72972ec7197348e |
| turbo-cache-control | no-preview |
| 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 |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 3215163789b3dc58dba97bd78a30c20c949f477f |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width