Title: lru_cache classmethod: variable has type "Self" after assignment · Issue #18993 · python/mypy · GitHub
Open Graph Title: lru_cache classmethod: variable has type "Self" after assignment · Issue #18993 · python/mypy
X Title: lru_cache classmethod: variable has type "Self" after assignment · Issue #18993 · python/mypy
Description: https://mypy-play.net/?mypy=latest&python=3.11&gist=81326668cbc8056d8f3b44d3396ea0d0 If I have a lru_cache decorated classmethod, I noticed that I can get an error where the return type will be literally Self rather than the inferred cla...
Open Graph Description: https://mypy-play.net/?mypy=latest&python=3.11&gist=81326668cbc8056d8f3b44d3396ea0d0 If I have a lru_cache decorated classmethod, I noticed that I can get an error where the return type will be lit...
X Description: https://mypy-play.net/?mypy=latest&python=3.11&gist=81326668cbc8056d8f3b44d3396ea0d0 If I have a lru_cache decorated classmethod, I noticed that I can get an error where the return type wil...
Opengraph URL: https://github.com/python/mypy/issues/18993
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"lru_cache classmethod: variable has type \"Self\" after assignment","articleBody":"https://mypy-play.net/?mypy=latest&python=3.11&gist=81326668cbc8056d8f3b44d3396ea0d0\n\nIf I have a lru_cache decorated classmethod, I noticed that I can get an error where the return type will be literally Self rather than the inferred class. I've seen a lot of discussion about lru_cache support, but it wasn't clear to me if this would be a dupe.\n\n**To Reproduce**\n\n```python\nfrom typing import Self\nfrom functools import lru_cache\n\nclass A:\n @classmethod\n @lru_cache\n def a(cls) -> Self:\n return cls()\n \n \n \nx = id(A)\n\nif x == 1:\n aa = A.a()\nelse:\n aa = A() # Incompatible types in assignment (expression has type \"A\", variable has type \"Self\") [assignment]\n```\n\n**Expected Behavior**\n\nI expected this code to have no type errors\n\n**Actual Behavior**\n\nmain.py:17: error: Incompatible types in assignment (expression has type \"A\", variable has type \"Self\") [assignment]\nFound 1 error in 1 file (checked 1 source file)\n\n**Your Environment**\n\nmypy 1.15, python 3.11, stock config\n","author":{"url":"https://github.com/Redoubts","@type":"Person","name":"Redoubts"},"datePublished":"2025-04-28T20:13:50Z","url":"https://github.com/python/mypy/issues/18993"}
| 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:436f0574-82f8-cb67-7b72-9f43d14e512e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BA0C:10F75B:10F8E0A:1661212:6B000C63 |
| html-safe-nonce | 64a3fc4890eb14b45503a00a084243c176be8fd46143f68f6a49970c44f576f6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQTBDOjEwRjc1QjoxMEY4RTBBOjE2NjEyMTI6NkIwMDBDNjMiLCJ2aXNpdG9yX2lkIjoiNjg2MzMxNTAxNDQ2ODUwNDY3NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | c56fd197d5e15bd1bc994436f7babb1fcfdec0c2670f850f9e45fa8c8808d22c |
| hovercard-subject-tag | issue:3026055401 |
| 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/mypy/18993/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3fe838e21001f9eced0cf8ff2b8dd90b1d4279b404e108138b2272d015acdc78/python/mypy/issues/18993 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3fe838e21001f9eced0cf8ff2b8dd90b1d4279b404e108138b2272d015acdc78/python/mypy/issues/18993 |
| og:image:alt | https://mypy-play.net/?mypy=latest&python=3.11&gist=81326668cbc8056d8f3b44d3396ea0d0 If I have a lru_cache decorated classmethod, I noticed that I can get an error where the return type will be lit... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Redoubts |
| hostname | github.com |
| expected-hostname | github.com |
| None | 0a0d8686a27478df474dd7415776a7a080cde8838b3cd92ea7601187572e5729 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/mypy git https://github.com/python/mypy.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 7053637 |
| octolytics-dimension-repository_nwo | python/mypy |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 7053637 |
| octolytics-dimension-repository_network_root_nwo | python/mypy |
| 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 | 16a11879678aaf97e2a42c33ee70830aa084fa37 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width