Title: Incorrect handling of Self when operating on the different class instance than self · Issue #14635 · python/mypy · GitHub
Open Graph Title: Incorrect handling of Self when operating on the different class instance than self · Issue #14635 · python/mypy
X Title: Incorrect handling of Self when operating on the different class instance than self · Issue #14635 · python/mypy
Description: Bug Report mypy complains on a method returning Self when it returns another instance of its own class. To Reproduce from typing import Self class Foo: def spawn(self) -> Self: return Foo() Expected Behavior The same output as with class...
Open Graph Description: Bug Report mypy complains on a method returning Self when it returns another instance of its own class. To Reproduce from typing import Self class Foo: def spawn(self) -> Self: return Foo() Expecte...
X Description: Bug Report mypy complains on a method returning Self when it returns another instance of its own class. To Reproduce from typing import Self class Foo: def spawn(self) -> Self: return Foo() Expe...
Opengraph URL: https://github.com/python/mypy/issues/14635
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Incorrect handling of Self when operating on the different class instance than self","articleBody":"\u003c!--\r\nIf you're not sure whether what you're experiencing is a mypy bug, please see the \"Question and Help\" form instead.\r\nPlease consider:\r\n\r\n- checking our common issues page: https://mypy.readthedocs.io/en/stable/common_issues.html\r\n- searching our issue tracker: https://github.com/python/mypy/issues to see if it's already been reported\r\n- asking on gitter chat: https://gitter.im/python/typing\r\n-->\r\n\r\n**Bug Report**\r\n\r\nmypy complains on a method returning `Self` when it returns another instance of its own class.\r\n\r\n**To Reproduce**\r\n\r\n```python\r\nfrom typing import Self\r\nclass Foo:\r\n def spawn(self) -> Self:\r\n return Foo()\r\n```\r\n\r\n**Expected Behavior**\r\n\r\nThe same output as with\r\n```python\r\nclass Foo:\r\n def spawn(self) -> 'Foo':\r\n return Foo()\r\n```\r\n\r\n**Actual Behavior**\r\n\r\n```\r\n1.py:4: error: Incompatible return value type (got \"Foo\", expected \"Self\") [return-value]\r\nFound 1 error in 1 file (checked 1 source file)\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: `mypy 1.0.0 (compiled: no)`\r\n- Mypy command-line flags: -\r\n- Mypy configuration options from `mypy.ini` (and other config files): -\r\n- Python version used: `Python 3.11.1`\r\n","author":{"url":"https://github.com/AMDmi3","@type":"Person","name":"AMDmi3"},"datePublished":"2023-02-07T13:18:44Z","url":"https://github.com/python/mypy/issues/14635"}
| 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:2bf892e8-f2c8-11c0-68d0-d1f99a0140a3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BD56:3FDF0C:D5337C:11C816A:6B00515B |
| html-safe-nonce | b347a45b4dacaf38d9ceb1deb7c2395d42a982311133ee3cf1d0f43561cc77b0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRDU2OjNGREYwQzpENTMzN0M6MTFDODE2QTo2QjAwNTE1QiIsInZpc2l0b3JfaWQiOiI2MTI4NTU1MzEzOTYxMzkwNDI3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 053610c5cb0334df4908beb06fa97de7e644a15904c15eb10f3fe6be302781d3 |
| hovercard-subject-tag | issue:1574319977 |
| 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/14635/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c5bff1aa9043d4ad6ae161f5a4f780a58f563c5f8c938be40457ed5e2641ea2b/python/mypy/issues/14635 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c5bff1aa9043d4ad6ae161f5a4f780a58f563c5f8c938be40457ed5e2641ea2b/python/mypy/issues/14635 |
| og:image:alt | Bug Report mypy complains on a method returning Self when it returns another instance of its own class. To Reproduce from typing import Self class Foo: def spawn(self) -> Self: return Foo() Expecte... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | AMDmi3 |
| hostname | github.com |
| expected-hostname | github.com |
| None | f420f4996e6b1ff1ccd6d7683f8134f4b5f0f8a50124c210dbfe7490e5644abb |
| 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 | 26e00df917aba0f128135dc073ea0c5e33a70d40 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width