Title: Property setter parameter type-checked against getter return type instead of setter parameter type · Issue #12900 · python/mypy · GitHub
Open Graph Title: Property setter parameter type-checked against getter return type instead of setter parameter type · Issue #12900 · python/mypy
X Title: Property setter parameter type-checked against getter return type instead of setter parameter type · Issue #12900 · python/mypy
Description: Bug Report As shown in the code under To Reproduce, mypy checks the value that is set on an attribute not against that attribute's setter's parameter type (Iterable[Member]), but against the getter's return type (List[Member]). While it ...
Open Graph Description: Bug Report As shown in the code under To Reproduce, mypy checks the value that is set on an attribute not against that attribute's setter's parameter type (Iterable[Member]), but against the getter...
X Description: Bug Report As shown in the code under To Reproduce, mypy checks the value that is set on an attribute not against that attribute's setter's parameter type (Iterable[Member]), but against th...
Opengraph URL: https://github.com/python/mypy/issues/12900
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Property setter parameter type-checked against getter return type instead of setter parameter type","articleBody":"**Bug Report**\r\nAs shown in the code under *To Reproduce*, mypy checks the value that is set on an attribute not against that attribute's setter's parameter type (`Iterable[Member]`), but against the getter's return type (`List[Member]`). While it may not be common for a setter to accept a supertype of the type returned by the getter, or even a completely unrelated and incompatible type, there are valid reasons to do so and mypy should not make the assumption that both types are identical.\r\n\r\n**To Reproduce**\r\n\r\n```python\r\nfrom typing import List, Iterable\r\n\r\n\r\nclass Member:\r\n pass\r\n\r\n\r\nclass Group:\r\n @property\r\n def members(self) -> List[Member]:\r\n pass\r\n\r\n @members.setter\r\n def members(self, members: Iterable[Member]) -> None:\r\n pass\r\n\r\n\r\ngroup = Group()\r\ngroup.members = {Member(), Member()}\r\n\r\n# mypy error: test.py:19: error: Incompatible types in assignment (expression has type \"Set[Member]\", variable has type \"List[Member]\")\r\n```\r\n\r\n**Expected Behavior**\r\n\r\nNo errors raised by mypy at all.\r\n\r\n**Actual Behavior**\r\n\r\nmypy erraneously flags the type of the value set on the attribute as incompatible.\r\n\r\n**Your Environment**\r\n\r\n- Mypy version used: 0.950\r\n- Mypy command-line flags: N/A\r\n- Mypy configuration options from `mypy.ini` (and other config files):\r\n ```\r\n check_untyped_defs = True\r\n no_implicit_optional = True\r\n ```\r\n- Python version used: 3.9\r\n- Operating system and version: Ubuntu 21.10","author":{"url":"https://github.com/bartfeenstra","@type":"Person","name":"bartfeenstra"},"datePublished":"2022-05-29T00:10:10Z","url":"https://github.com/python/mypy/issues/12900"}
| 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:0f48921e-aa59-5169-c57c-b510cd220faf |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EB72:106F5D:3B22C2:4F9552:6B002A4B |
| html-safe-nonce | 36987fb6339dfa89698d1fe19d82f7d95f351b3ffd23d1149ac0b2687f664fad |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQjcyOjEwNkY1RDozQjIyQzI6NEY5NTUyOjZCMDAyQTRCIiwidmlzaXRvcl9pZCI6IjQyNDA1MTMzNjU5NTQyNzU5MTUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 5c49c5528a7870fd99ea66a6f7e67986dca838598a8407cd6ad4970c8f2aac22 |
| hovercard-subject-tag | issue:1251750241 |
| 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/12900/issue_layout |
| twitter:image | https://opengraph.githubassets.com/91a99869a4e52dd1c50355c17f0be997088ff3a0673bb046e7e085e7af174108/python/mypy/issues/12900 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/91a99869a4e52dd1c50355c17f0be997088ff3a0673bb046e7e085e7af174108/python/mypy/issues/12900 |
| og:image:alt | Bug Report As shown in the code under To Reproduce, mypy checks the value that is set on an attribute not against that attribute's setter's parameter type (Iterable[Member]), but against the getter... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | bartfeenstra |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7d0829bbde9e48b2486cb5dd6d147896eb01d32134627091f818958a935ef3f0 |
| 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 | f3f3a43ca095cdea3abbb394112e971f9fdb94fa |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width