Title: False negative for restricted self in subclass · Issue #7861 · python/mypy · GitHub
Open Graph Title: False negative for restricted self in subclass · Issue #7861 · python/mypy
X Title: False negative for restricted self in subclass · Issue #7861 · python/mypy
Description: This currently passes, but the code is unsafe: from typing import TypeVar, Generic T = TypeVar('T') class Base(Generic[T]): def __init__(self, item: T) -> None: self.item = item def foo(self) -> None: pass class Sub(Base[T]): def foo(sel...
Open Graph Description: This currently passes, but the code is unsafe: from typing import TypeVar, Generic T = TypeVar('T') class Base(Generic[T]): def __init__(self, item: T) -> None: self.item = item def foo(self) -> No...
X Description: This currently passes, but the code is unsafe: from typing import TypeVar, Generic T = TypeVar('T') class Base(Generic[T]): def __init__(self, item: T) -> None: self.item = item def foo(...
Opengraph URL: https://github.com/python/mypy/issues/7861
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"False negative for restricted self in subclass","articleBody":"This currently passes, but the code is unsafe:\r\n```python\r\nfrom typing import TypeVar, Generic\r\n\r\nT = TypeVar('T')\r\n\r\nclass Base(Generic[T]):\r\n def __init__(self, item: T) -> None:\r\n self.item = item\r\n def foo(self) -> None:\r\n pass\r\n\r\nclass Sub(Base[T]):\r\n def foo(self: Sub[str]) -> None:\r\n self.item + 'no'\r\n\r\n# This is why the above is unsafe.\r\na: Base[int] = Sub(0)\r\na.foo()\r\n```\r\nOn one hand it is a very rare situation, on the other hand in view of making explicit self-types a more \"official\" feature (see https://github.com/python/mypy/pull/7860) we might want to fix this.\r\n\r\nAlso it would be great to fix this in a consistent way, so that the fix also works for same issue with multiple inheritance without code duplication (see https://github.com/python/mypy/issues/7724).","author":{"url":"https://github.com/ilevkivskyi","@type":"Person","name":"ilevkivskyi"},"datePublished":"2019-11-03T09:32:27Z","url":"https://github.com/python/mypy/issues/7861"}
| 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:f05b7eb6-3ed8-d4e1-9e74-ed34f56e0c15 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CC18:3B10DD:C5EB5C:1015848:6AFFF1B0 |
| html-safe-nonce | 8c8598011d3a235b878ec6c9ba8a2a51f52ad83dd7859d91df3b20210c20fc3f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQzE4OjNCMTBERDpDNUVCNUM6MTAxNTg0ODo2QUZGRjFCMCIsInZpc2l0b3JfaWQiOiIyNDMyMTkyMTE0MTA5NDQ0NTI4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | c9420949a813a422f2c67843e0fbe51661c19ac59aef9da552a2e9cacb4e2799 |
| hovercard-subject-tag | issue:516802396 |
| 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/7861/issue_layout |
| twitter:image | https://opengraph.githubassets.com/dbc6d2de14de2fbf962b5e03137686317b8f33de89f1cff8ac64b9ec4f2ca9ee/python/mypy/issues/7861 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/dbc6d2de14de2fbf962b5e03137686317b8f33de89f1cff8ac64b9ec4f2ca9ee/python/mypy/issues/7861 |
| og:image:alt | This currently passes, but the code is unsafe: from typing import TypeVar, Generic T = TypeVar('T') class Base(Generic[T]): def __init__(self, item: T) -> None: self.item = item def foo(self) -> No... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ilevkivskyi |
| 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