Title: Cachetools timer with datetime.now · Issue #8459 · python/typeshed · GitHub
Open Graph Title: Cachetools timer with datetime.now · Issue #8459 · python/typeshed
X Title: Cachetools timer with datetime.now · Issue #8459 · python/typeshed
Description: A followup to the issue presented in #6953, I'm running into mypy errors when implementing a cache using the mechanism as defined in the cachetools documentation. Cachetools documentation for TRLUCache with example that matches the imple...
Open Graph Description: A followup to the issue presented in #6953, I'm running into mypy errors when implementing a cache using the mechanism as defined in the cachetools documentation. Cachetools documentation for TRLUC...
X Description: A followup to the issue presented in #6953, I'm running into mypy errors when implementing a cache using the mechanism as defined in the cachetools documentation. Cachetools documentation for T...
Opengraph URL: https://github.com/python/typeshed/issues/8459
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Cachetools timer with datetime.now","articleBody":"A followup to the issue presented in #6953, I'm running into mypy errors when implementing a cache using the mechanism as defined in the cachetools documentation.\r\n\r\n[Cachetools documentation for TRLUCache](https://cachetools.readthedocs.io/en/latest/#cachetools.TLRUCache) with example that matches the implementation below.\r\n\r\n### My implementation\r\n\r\n```\r\ndef expires_in_ttu(_key, value, now):\r\n expires_in = value[1]\r\n return now + timedelta(seconds=expires_in)\r\n\r\ncache = TLRUCache(maxsize=10, ttu=expires_in_ttu, timer=datetime.now)\r\n```\r\n\r\nThe mypy error:\r\n\r\n```\r\nArgument \"timer\" to \"TLRUCache\" has incompatible type \"Callable[[Optional[tzinfo]], datetime]\"; expected \"Callable[[], float]\"\r\n```\r\n\r\nWorkaround:\r\n\r\nWe can use `time.monotonic` instead of `datetime.now`, but:\r\n - the example in the docs use datetime.now\r\n - datetime.now is arguably more familiar to most developers\r\n\r\n### Versions\r\n\r\n- cachetools: 5.2.0\r\n- types-cachetools: 5.2.1","author":{"url":"https://github.com/m3brown","@type":"Person","name":"m3brown"},"datePublished":"2022-08-01T18:31:46Z","url":"https://github.com/python/typeshed/issues/8459"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:eba6d6fa-35a9-6548-a008-324e57d1acd3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B2AA:2FD3CB:3EAEE5:545E2B:6B002BBF |
| html-safe-nonce | 471620382c18d1e3c812c08361462a0311f614e89d089aaf765b3b91ded1061d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMkFBOjJGRDNDQjozRUFFRTU6NTQ1RTJCOjZCMDAyQkJGIiwidmlzaXRvcl9pZCI6IjE2NTQ4MzAyMDM0OTY1NzM4ODgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | c3a837015ee524e9dbbb5506835308b3df3d5f684ddc32d94e3e9e18a90e67be |
| hovercard-subject-tag | issue:1324813040 |
| 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/typeshed/8459/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2f196ef0a8d14fc81e334f5ec35110786a570a442a7048d7d19e45cb6301c4ca/python/typeshed/issues/8459 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2f196ef0a8d14fc81e334f5ec35110786a570a442a7048d7d19e45cb6301c4ca/python/typeshed/issues/8459 |
| og:image:alt | A followup to the issue presented in #6953, I'm running into mypy errors when implementing a cache using the mechanism as defined in the cachetools documentation. Cachetools documentation for TRLUC... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | m3brown |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7d0829bbde9e48b2486cb5dd6d147896eb01d32134627091f818958a935ef3f0 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/typeshed git https://github.com/python/typeshed.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 31696383 |
| octolytics-dimension-repository_nwo | python/typeshed |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 31696383 |
| octolytics-dimension-repository_network_root_nwo | python/typeshed |
| 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 | f3f3a43ca095cdea3abbb394112e971f9fdb94fa |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width