Title: generic is incorrectly inferred as invariant if class uses `Self` type on an attribute · Issue #18334 · python/mypy · GitHub
Open Graph Title: generic is incorrectly inferred as invariant if class uses `Self` type on an attribute · Issue #18334 · python/mypy
X Title: generic is incorrectly inferred as invariant if class uses `Self` type on an attribute · Issue #18334 · python/mypy
Description: from typing import Self class Foo[T]: instance: Self # commenting out this line makes the error go away def foo(self) -> T: ... # type:ignore[empty-body] class Bar(Foo[int]): ... # Incompatible types in assignment (expression has type "B...
Open Graph Description: from typing import Self class Foo[T]: instance: Self # commenting out this line makes the error go away def foo(self) -> T: ... # type:ignore[empty-body] class Bar(Foo[int]): ... # Incompatible typ...
X Description: from typing import Self class Foo[T]: instance: Self # commenting out this line makes the error go away def foo(self) -> T: ... # type:ignore[empty-body] class Bar(Foo[int]): ... # Incompatible ...
Opengraph URL: https://github.com/python/mypy/issues/18334
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"generic is incorrectly inferred as invariant if class uses `Self` type on an attribute","articleBody":"```py\r\nfrom typing import Self\r\n\r\n\r\nclass Foo[T]:\r\n instance: Self # commenting out this line makes the error go away\r\n\r\n def foo(self) -> T: ... # type:ignore[empty-body]\r\n\r\n\r\nclass Bar(Foo[int]): ...\r\n\r\n# Incompatible types in assignment (expression has type \"Bar\", variable has type \"Foo[object]\") [assignment]\r\nfoo: Foo[object] = Bar()\r\n```\r\n[playground](https://mypy-play.net/?mypy=latest&python=3.13&flags=show-error-codes%2Cstrict%2Ccheck-untyped-defs%2Cdisallow-any-decorated%2Cdisallow-any-expr%2Cdisallow-any-explicit%2Cdisallow-any-generics%2Cdisallow-any-unimported%2Cdisallow-incomplete-defs%2Cdisallow-subclassing-any%2Cdisallow-untyped-calls%2Cdisallow-untyped-decorators%2Cdisallow-untyped-defs%2Cno-implicit-reexport%2Clocal-partial-types%2Cwarn-redundant-casts%2Cwarn-return-any%2Cwarn-unreachable%2Cwarn-unused-configs%2Cwarn-unused-ignores&gist=efefed751bdb0d6af3282c0ba018a5f8)","author":{"url":"https://github.com/DetachHead","@type":"Person","name":"DetachHead"},"datePublished":"2024-12-24T07:07:05Z","url":"https://github.com/python/mypy/issues/18334"}
| 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:1e6418dc-c4c2-7868-138d-7de1cee961db |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AE10:302FC:1074891:1616CC7:6B005E2B |
| html-safe-nonce | 31c0604f5c302f38e16d11378eb8a488b4dc7bad8d4c7449657ff6e5492b952f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRTEwOjMwMkZDOjEwNzQ4OTE6MTYxNkNDNzo2QjAwNUUyQiIsInZpc2l0b3JfaWQiOiI2OTU3MzA3NzgzODc2MjA2MTIzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 738e0a89ad8c9feb7fc5730cf6112ae39b64f351e6cd61f703377656991c3248 |
| hovercard-subject-tag | issue:2757308008 |
| 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/18334/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1a4ce24006271bde4075dd1df857130d4155690f7c9db9609345452c6befabf8/python/mypy/issues/18334 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1a4ce24006271bde4075dd1df857130d4155690f7c9db9609345452c6befabf8/python/mypy/issues/18334 |
| og:image:alt | from typing import Self class Foo[T]: instance: Self # commenting out this line makes the error go away def foo(self) -> T: ... # type:ignore[empty-body] class Bar(Foo[int]): ... # Incompatible typ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | DetachHead |
| hostname | github.com |
| expected-hostname | github.com |
| None | 29be975efff6507a5d135de9c7d634cf7ff8f0c55222a64386ab3202209aaf73 |
| 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 | eacd927ba6112e3b01ba99c762bd699a4a4f5df7 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width