Title: Type override for attributes is not checked · Issue #2211 · python/mypy · GitHub
Open Graph Title: Type override for attributes is not checked · Issue #2211 · python/mypy
X Title: Type override for attributes is not checked · Issue #2211 · python/mypy
Description: from what I see, overriding an attribute with an incompatible type (which can lead to unsoundness) does not produce any kind of warning with mypy: class Base: attr = "foo" def f(self) -> str: return self.attr class Derived(Base): attr = ...
Open Graph Description: from what I see, overriding an attribute with an incompatible type (which can lead to unsoundness) does not produce any kind of warning with mypy: class Base: attr = "foo" def f(self) -> str: retur...
X Description: from what I see, overriding an attribute with an incompatible type (which can lead to unsoundness) does not produce any kind of warning with mypy: class Base: attr = "foo" def f(self) -&g...
Opengraph URL: https://github.com/python/mypy/issues/2211
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Type override for attributes is not checked","articleBody":"from what I see, overriding an attribute with an incompatible type (which can lead to unsoundness) does not produce any kind of warning with mypy:\n\n``` python\nclass Base:\n attr = \"foo\"\n\n def f(self) -> str:\n return self.attr\n\nclass Derived(Base):\n attr = 42\n\nd = Derived()\n\nreveal_type(d.f())\n```\n\nThe code above shows that mypy thinks that the `d.f()` expression is a string, while it's actually an int. Shouldn't this kind of redefinitions be forbidden?\n","author":{"url":"https://github.com/dmoisset","@type":"Person","name":"dmoisset"},"datePublished":"2016-10-03T14:25:32Z","url":"https://github.com/python/mypy/issues/2211"}
| 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:52153ce9-c92c-6448-a82b-ac3bf4495094 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AD18:1DF7D7:3A1F85:513DAA:6B005E1C |
| html-safe-nonce | 20be45ca4782f05df066a4a973739b208c89429b8272966c99bbbde820ccdd6e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRDE4OjFERjdENzozQTFGODU6NTEzREFBOjZCMDA1RTFDIiwidmlzaXRvcl9pZCI6Ijk0NTI1MDEyMjQyNDQwOTYyOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 5eff8def17a15329f257938072cf7543f0416ecd6c8eada984d9146526200b10 |
| hovercard-subject-tag | issue:180654047 |
| 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/2211/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3bfab5f4d79d79caaf0c0e911b79a998e2d18788144f869ab82bf7c023ea21dd/python/mypy/issues/2211 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3bfab5f4d79d79caaf0c0e911b79a998e2d18788144f869ab82bf7c023ea21dd/python/mypy/issues/2211 |
| og:image:alt | from what I see, overriding an attribute with an incompatible type (which can lead to unsoundness) does not produce any kind of warning with mypy: class Base: attr = "foo" def f(self) -> str: retur... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dmoisset |
| 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