Title: My 1.5.1 gets confused when a class variable references a method from another class that returns `Self`. · Issue #15934 · python/mypy · GitHub
Open Graph Title: My 1.5.1 gets confused when a class variable references a method from another class that returns `Self`. · Issue #15934 · python/mypy
X Title: My 1.5.1 gets confused when a class variable references a method from another class that returns `Self`. · Issue #15934 · python/mypy
Description: Bug Report When you define a class variable on a class that references a method that returns Self from another class, MyPy thinks that Self is the class where the method is referenced/ To Reproduce from typing import Self class Foo: def ...
Open Graph Description: Bug Report When you define a class variable on a class that references a method that returns Self from another class, MyPy thinks that Self is the class where the method is referenced/ To Reproduce...
X Description: Bug Report When you define a class variable on a class that references a method that returns Self from another class, MyPy thinks that Self is the class where the method is referenced/ To Reproduce...
Opengraph URL: https://github.com/python/mypy/issues/15934
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"My 1.5.1 gets confused when a class variable references a method from another class that returns `Self`.","articleBody":"**Bug Report**\r\n\r\nWhen you define a class variable on a class that references a method that returns `Self` from another class, MyPy thinks that `Self` is the class where the method is referenced/\r\n\r\n**To Reproduce**\r\n\r\n```python\r\nfrom typing import Self\r\n\r\n\r\nclass Foo:\r\n def foo(self) -> Self:\r\n return self\r\n\r\n\r\nclass Ben:\r\n MY_MAP = {\r\n \"foo\": Foo.foo,\r\n }\r\n\r\n @classmethod\r\n def doit(cls) -> Foo:\r\n foo_method = cls.MY_MAP[\"foo\"]\r\n return foo_method(Foo())\r\n\r\n\r\nassert isinstance(Ben.doit(), Foo)\r\n```\r\n\r\n**Expected Behavior**\r\n\r\nMypy should not detect any errors.\r\n\r\n**Actual Behavior**\r\n\r\n```\r\nben.py:17: error: Incompatible return value type (got \"Ben\", expected \"Foo\") [return-value]\r\nben.py:17: error: Argument 1 has incompatible type \"Foo\"; expected \"Ben\" [arg-type]\r\n```\r\n\r\n**Your Environment**\r\n\r\n\u003c!-- Include as many relevant details about the environment you experienced the bug in -->\r\n\r\n- Mypy version used: 1.5.1\r\n- Mypy command-line flags: None\r\n- Mypy configuration options from `mypy.ini` (and other config files):\r\n\r\n```\r\nplugins = [\r\n \"pydantic.mypy\"\r\n]\r\nexplicit_package_bases = true\r\npython_version = \"3.11\"\r\ncheck_untyped_defs = true\r\nexclude = '''\r\n(?x)(\r\n ^.*flycheck.*$\r\n | ^.*#.*$\r\n )\r\n'''\r\n```\r\n- Python version used: 3.11\r\n\r\n","author":{"url":"https://github.com/benwah","@type":"Person","name":"benwah"},"datePublished":"2023-08-22T18:57:29Z","url":"https://github.com/python/mypy/issues/15934"}
| 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:34bf6223-7eef-9f63-78e6-616dbf2bf775 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9400:18E7F5:11C6E20:17576B1:6B000CBF |
| html-safe-nonce | 4e68794cf1c8d7b957e468749325aa8fb533c0ae0567dabdd77236b809631e30 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NDAwOjE4RTdGNToxMUM2RTIwOjE3NTc2QjE6NkIwMDBDQkYiLCJ2aXNpdG9yX2lkIjoiODQ0ODE1ODg0NDM0MDY2OTYzMSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 92794d245e2cf0e9ebb5d38f96596d76929576a22f17f203c8e6f102eb1b2680 |
| hovercard-subject-tag | issue:1862026638 |
| 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/15934/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5b3108819974e6cf5c9359b97ac26429609985dd8badeb19912097cd498a2adf/python/mypy/issues/15934 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5b3108819974e6cf5c9359b97ac26429609985dd8badeb19912097cd498a2adf/python/mypy/issues/15934 |
| og:image:alt | Bug Report When you define a class variable on a class that references a method that returns Self from another class, MyPy thinks that Self is the class where the method is referenced/ To Reproduce... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | benwah |
| hostname | github.com |
| expected-hostname | github.com |
| None | cf7ee0062053ad9eb05b6e5de57bd96c2055708bcbada4144946b5ec129cf1d7 |
| 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 | 9cab7de176a56362d2aabcbb4d1e07e846eba8a0 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width