Title: False positive with inherited writable property that reads subtype in subclass · Issue #14301 · python/mypy · GitHub
Open Graph Title: False positive with inherited writable property that reads subtype in subclass · Issue #14301 · python/mypy
X Title: False positive with inherited writable property that reads subtype in subclass · Issue #14301 · python/mypy
Description: If I run mypy on the following code: class Base: value = 123 @property def x(self) -> int: return self.value @x.setter def x(self, value: int) -> None: self.value = value class Sub(Base): @property def x(self) -> bool: return self.value ...
Open Graph Description: If I run mypy on the following code: class Base: value = 123 @property def x(self) -> int: return self.value @x.setter def x(self, value: int) -> None: self.value = value class Sub(Base): @property...
X Description: If I run mypy on the following code: class Base: value = 123 @property def x(self) -> int: return self.value @x.setter def x(self, value: int) -> None: self.value = value class Sub(Base): @pr...
Opengraph URL: https://github.com/python/mypy/issues/14301
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"False positive with inherited writable property that reads subtype in subclass","articleBody":"If I run mypy on the following code:\r\n\r\n```py\r\nclass Base:\r\n value = 123\r\n\r\n @property\r\n def x(self) -> int:\r\n return self.value\r\n\r\n @x.setter\r\n def x(self, value: int) -> None:\r\n self.value = value\r\n\r\nclass Sub(Base):\r\n @property\r\n def x(self) -> bool:\r\n return self.value != 0\r\n \r\n @x.setter\r\n def x(self, value: int) -> None:\r\n self.value = value\r\n```\r\n\r\nIt reports:\r\n```\r\nerror: Signature of \"x\" incompatible with supertype \"Base\" [override]\r\n```\r\n\r\nI'd expect mypy to not report any error, as `bool` is a subtype of `int` and therefore the property type returned by the subclass always conforms to the property type defined in the superclass.\r\n\r\nThis problem only occurs for writable properties: if I remove the setter definitions from both the superclass and the subclass, no false positive is reported.\r\n\r\nI can produce this problem using mypy 0.991 on Python 3.10.8. When using mypy 0.981 instead, no false positive is reported.\r\n","author":{"url":"https://github.com/mthuurne","@type":"Person","name":"mthuurne"},"datePublished":"2022-12-15T21:46:27Z","url":"https://github.com/python/mypy/issues/14301"}
| 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:dbc563d1-5a3d-b5f6-c1cd-ba144241bdda |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 93C6:1A77D:107E28:163CD0:6B001DC1 |
| html-safe-nonce | cf47bb80e430f198ed278f3e7007f8bc829cdcdf86981889faddb9fe5576d5e9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5M0M2OjFBNzdEOjEwN0UyODoxNjNDRDA6NkIwMDFEQzEiLCJ2aXNpdG9yX2lkIjoiNjQ4MjIwMjQxMDAxMjkwODk5MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 9b48f32236d77a4ab1eb159a4c7c9db5fcdcc0fc179cd42cdd2abdaaed8eb62f |
| hovercard-subject-tag | issue:1499152181 |
| 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/14301/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1721d3c5ee6a799b4f2cc14bc183079151b40face24cbd8cfa013521e797570f/python/mypy/issues/14301 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1721d3c5ee6a799b4f2cc14bc183079151b40face24cbd8cfa013521e797570f/python/mypy/issues/14301 |
| og:image:alt | If I run mypy on the following code: class Base: value = 123 @property def x(self) -> int: return self.value @x.setter def x(self, value: int) -> None: self.value = value class Sub(Base): @property... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mthuurne |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4eb4cba0d69f045374ac15de9666d22b0961e1d555cc3824f36b7734c00c78e0 |
| 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 | 44c658b24abf00491fb7ae5f56d42c9f38cbeab2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width