Title: Final variable is mutable when using structural subtyping · Issue #10850 · python/mypy · GitHub
Open Graph Title: Final variable is mutable when using structural subtyping · Issue #10850 · python/mypy
X Title: Final variable is mutable when using structural subtyping · Issue #10850 · python/mypy
Description: Bug Report Under structural subtyping with a variable narrowed to Final, it's possible to modify the var contents To Reproduce # poc.py from dataclasses import dataclass from typing import Protocol, Final @dataclass class FinalY: y: Fina...
Open Graph Description: Bug Report Under structural subtyping with a variable narrowed to Final, it's possible to modify the var contents To Reproduce # poc.py from dataclasses import dataclass from typing import Protocol...
X Description: Bug Report Under structural subtyping with a variable narrowed to Final, it's possible to modify the var contents To Reproduce # poc.py from dataclasses import dataclass from typing import Prot...
Opengraph URL: https://github.com/python/mypy/issues/10850
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Final variable is mutable when using structural subtyping","articleBody":"**Bug Report**\r\n\r\nUnder structural subtyping with a variable narrowed to `Final`, it's possible to modify the var contents\r\n\r\n**To Reproduce**\r\n```\r\n# poc.py\r\nfrom dataclasses import dataclass\r\nfrom typing import Protocol, Final\r\n\r\n@dataclass\r\nclass FinalY:\r\n y: Final[int] = 0\r\n\r\nclass Y(Protocol):\r\n y: int\r\n\r\ndef f(x: Y) -> Y:\r\n x.y = 42\r\n return x\r\n\r\nprint(f(FinalY(17)))\r\n```\r\n\r\n>$ mypy poc.py \r\n>Success: no issues found in 1 source file\r\n\r\n>$ python poc.py\r\n>FinalY(y=42)\r\n\r\n**Expected Behavior**\r\n\r\nClass with a variable `Final[T]` should not be a structural subtype of a protocol with variable `T`\r\n\r\n**Your Environment**\r\n\r\n- Mypy version used: 0.910\r\n- Python version used: 3.9.6\r\n\r\n\r\n_This bug was inspired by @erictraut's [example of how to deal with other kind of issue](https://github.com/python/mypy/issues/5374#issuecomment-884220116)_","author":{"url":"https://github.com/Tomatosoup97","@type":"Person","name":"Tomatosoup97"},"datePublished":"2021-07-21T15:35:10Z","url":"https://github.com/python/mypy/issues/10850"}
| 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:23564ac8-929e-0fbe-7bfa-11e550c9c556 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D95E:370586:8A733:C1ED3:6B005167 |
| html-safe-nonce | 6a7c5bbdea7a00bd8fdf5ea03b5f978f28bfa1429e77e23e15cbba5709fe7504 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEOTVFOjM3MDU4Njo4QTczMzpDMUVEMzo2QjAwNTE2NyIsInZpc2l0b3JfaWQiOiIzMzkwOTA3NTg0Mjc2ODc3NjcxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 518c601733f3d136dc7b80cd9bd2b4f1ec0553cefbe6248ba4e1453df2fb9e1c |
| hovercard-subject-tag | issue:949848900 |
| 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/10850/issue_layout |
| twitter:image | https://opengraph.githubassets.com/0f436177981a37dab261351c4015626b5f714d753e946174e66c458c2fa41619/python/mypy/issues/10850 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/0f436177981a37dab261351c4015626b5f714d753e946174e66c458c2fa41619/python/mypy/issues/10850 |
| og:image:alt | Bug Report Under structural subtyping with a variable narrowed to Final, it's possible to modify the var contents To Reproduce # poc.py from dataclasses import dataclass from typing import Protocol... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Tomatosoup97 |
| hostname | github.com |
| expected-hostname | github.com |
| None | f420f4996e6b1ff1ccd6d7683f8134f4b5f0f8a50124c210dbfe7490e5644abb |
| 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 | 26e00df917aba0f128135dc073ea0c5e33a70d40 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width