Title: `functools.lru_cache` wrapped function with TypeVar has wrong return type. · Issue #6987 · python/typeshed · GitHub
Open Graph Title: `functools.lru_cache` wrapped function with TypeVar has wrong return type. · Issue #6987 · python/typeshed
X Title: `functools.lru_cache` wrapped function with TypeVar has wrong return type. · Issue #6987 · python/typeshed
Description: Hi, I think there is a problem when using functools.lru_cache (and functools.cache). When the decorated function uses a TypeVar for typing arguments and return type, the wrapped function returend by functools.lru_cache has wrong (or unre...
Open Graph Description: Hi, I think there is a problem when using functools.lru_cache (and functools.cache). When the decorated function uses a TypeVar for typing arguments and return type, the wrapped function returend b...
X Description: Hi, I think there is a problem when using functools.lru_cache (and functools.cache). When the decorated function uses a TypeVar for typing arguments and return type, the wrapped function returend b...
Opengraph URL: https://github.com/python/typeshed/issues/6987
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`functools.lru_cache` wrapped function with TypeVar has wrong return type.","articleBody":"Hi, \r\n\r\nI think there is a problem when using `functools.lru_cache` (and `functools.cache`). When the decorated function uses a `TypeVar` for typing arguments and return type, the wrapped function returend by `functools.lru_cache` has wrong (or unresolved) types.\r\nThis is not the case when replacing the `TypeVar` with an explicit type. See the mwe below. Thx.\r\n\r\n```python\r\nimport functools\r\nfrom typing import TypeVar\r\n\r\n_T = TypeVar(\"_T\")\r\n\r\n\r\ndef my_func(elem: _T) -> list[_T]:\r\n return [elem]\r\n \r\nmy_func_cached = functools.lru_cache(my_func)\r\n\r\na = my_func(\"a\")\r\nreveal_type(a) # Revealed type is \"builtins.list[builtins.str*]\"\r\na_c = my_func_cached(\"a\")\r\n\r\n# ERROR: this should be \"builtins.list*[builtins.str]\"\r\nreveal_type(a_c) # Revealed type is \"builtins.list*[_T`-1]\"\r\n\r\n\r\n# this works\r\n\r\ndef my_func_str(elem: str) -> list[str]:\r\n return [elem]\r\n \r\nmy_func_str_cached = functools.lru_cache(my_func_str)\r\n\r\na_str = my_func_str(\"a\")\r\nreveal_type(a_str) # Revealed type is \"builtins.list[builtins.str]\"\r\na_str_c = my_func_str_cached(\"a\")\r\nreveal_type(a_str_c) # Revealed type is \"builtins.list*[builtins.str]\"\r\n```\r\nRunning:\r\nPython 3.10.1\r\nmypy 0.931\r\nLinux 5.16.0-arch1-1","author":{"url":"https://github.com/yumasheta","@type":"Person","name":"yumasheta"},"datePublished":"2022-01-21T15:35:42Z","url":"https://github.com/python/typeshed/issues/6987"}
| 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:d000833c-5535-ec0f-c917-f2af1ec02441 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9158:3A782D:1DBB6:29403:6B001749 |
| html-safe-nonce | dd13ca3e096dd75ec5e5bf0dcc8c81ba5daa41cf0cead6d09365306beb94961e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MTU4OjNBNzgyRDoxREJCNjoyOTQwMzo2QjAwMTc0OSIsInZpc2l0b3JfaWQiOiI3ODQ4MzU5ODI4MTYxMzA0MzkzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | c577e0147deb2fb10e50b1fde7bb51c279b301f949ec4d69c10c6c82aac0e488 |
| hovercard-subject-tag | issue:1110601805 |
| 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/6987/issue_layout |
| twitter:image | https://opengraph.githubassets.com/998cfc6cc33dedc169ea5d864eb0d9bc68c643392744e5194fc0fcd5edda44d1/python/typeshed/issues/6987 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/998cfc6cc33dedc169ea5d864eb0d9bc68c643392744e5194fc0fcd5edda44d1/python/typeshed/issues/6987 |
| og:image:alt | Hi, I think there is a problem when using functools.lru_cache (and functools.cache). When the decorated function uses a TypeVar for typing arguments and return type, the wrapped function returend b... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | yumasheta |
| hostname | github.com |
| expected-hostname | github.com |
| None | a2dd2291b1b13cc9c06f27ec92fa3dbaf34116fc24c9347b8539db61884c59f4 |
| 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 | 70121d4e855ee0bb7b75cf15d061d91f8863c0f8 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width