Title: Return type is `Self` when calling an inherited decorated classmethod that returns `Self` · Issue #19023 · python/mypy · GitHub
Open Graph Title: Return type is `Self` when calling an inherited decorated classmethod that returns `Self` · Issue #19023 · python/mypy
X Title: Return type is `Self` when calling an inherited decorated classmethod that returns `Self` · Issue #19023 · python/mypy
Description: Bug Report When calling an inherited decorated classmethod that returns Self, mypy does not resolve the type and thinks the type of the return value is Self. To Reproduce https://mypy-play.net/?mypy=latest&python=3.13&flags=strict&gist=6...
Open Graph Description: Bug Report When calling an inherited decorated classmethod that returns Self, mypy does not resolve the type and thinks the type of the return value is Self. To Reproduce https://mypy-play.net/?myp...
X Description: Bug Report When calling an inherited decorated classmethod that returns Self, mypy does not resolve the type and thinks the type of the return value is Self. To Reproduce https://mypy-play.net/?myp...
Opengraph URL: https://github.com/python/mypy/issues/19023
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Return type is `Self` when calling an inherited decorated classmethod that returns `Self`","articleBody":"**Bug Report**\n\nWhen calling an inherited decorated classmethod that returns `Self`, mypy does not resolve the type and thinks the type of the return value is `Self`.\n\n**To Reproduce**\n\nhttps://mypy-play.net/?mypy=latest&python=3.13&flags=strict&gist=664aeee2f4339ce869129dfba8017289\n\n```python\nfrom __future__ import annotations\n\nfrom collections.abc import Callable\nfrom functools import wraps\nfrom typing import Any, Self, TypeVar\n\ntype JSON = dict[str, Any]\nT = TypeVar(\"T\")\n\n\ndef debug(make: Callable[[type[T], JSON], T]) -> Callable[[type[T], JSON], T]:\n @wraps(make)\n def wrapper(cls: type[T], data: JSON) -> T:\n return make(cls, data)\n\n return wrapper\n\n\nclass Foo:\n data: JSON\n \n def __init__(self, data: JSON) -> None:\n self.data = data\n\n @classmethod\n @debug\n def make(cls, data: JSON) -> Self:\n return cls(data)\n\n\nclass Bar(Foo):\n pass\n\n\ndef test() -> Bar:\n return Bar.make({})\n```\n\n**Expected Behavior**\n\nThe code should type check.\n\n**Actual Behavior**\n\n```\nmain.py:36: error: Incompatible return value type (got \"Self\", expected \"Bar\") [return-value]\nFound 1 error in 1 file (checked 1 source file)\n```\n\n**Your Environment**\n\n- Mypy version used: 1.15.0\n- Mypy command-line flags: `--strict`\n- Python version used: 3.13","author":{"url":"https://github.com/injust","@type":"Person","name":"injust"},"datePublished":"2025-05-04T04:02:55Z","url":"https://github.com/python/mypy/issues/19023"}
| 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:03ee7bd8-32d2-a003-cec4-6ba6de600110 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D7F0:1A7566:34C37F:4740AA:6B002835 |
| html-safe-nonce | 8c939ea80b6fffc3f64670ea07e711668da4b6c03f23f4c117c77d3999725364 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEN0YwOjFBNzU2NjozNEMzN0Y6NDc0MEFBOjZCMDAyODM1IiwidmlzaXRvcl9pZCI6IjkwMjkxMDg4OTQwMzAzNzQ5NjUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | b30989410d39e54193c69717d3cf337961e7a29c3c6005ee42f4ba6c09dd88a6 |
| hovercard-subject-tag | issue:3037761113 |
| 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/19023/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1405f09c898272cf7d2df00d4def7fe437c947168d041d513f290b74bf6270ec/python/mypy/issues/19023 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1405f09c898272cf7d2df00d4def7fe437c947168d041d513f290b74bf6270ec/python/mypy/issues/19023 |
| og:image:alt | Bug Report When calling an inherited decorated classmethod that returns Self, mypy does not resolve the type and thinks the type of the return value is Self. To Reproduce https://mypy-play.net/?myp... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | injust |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4eb4cba0d69f045374ac15de9666d22b0961e1d555cc3824f36b7734c00c78e0 |
| 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 | 44c658b24abf00491fb7ae5f56d42c9f38cbeab2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width