Title: generic mutable class attributes introduce a vent in the type system · Issue #11538 · python/mypy · GitHub
Open Graph Title: generic mutable class attributes introduce a vent in the type system · Issue #11538 · python/mypy
X Title: generic mutable class attributes introduce a vent in the type system · Issue #11538 · python/mypy
Description: from typing import Generic, TypeVar T = TypeVar("T") class A(Generic[T]): shared_attr: list[T] = [] a1 = A[str]() a1.shared_attr.append("AMONGUS") a2 = A[int]() a2.shared_attr.append(1) value = a2.class_attr[0] reveal_type(value) # revea...
Open Graph Description: from typing import Generic, TypeVar T = TypeVar("T") class A(Generic[T]): shared_attr: list[T] = [] a1 = A[str]() a1.shared_attr.append("AMONGUS") a2 = A[int]() a2.shared_attr.append(1) value = a2....
X Description: from typing import Generic, TypeVar T = TypeVar("T") class A(Generic[T]): shared_attr: list[T] = [] a1 = A[str]() a1.shared_attr.append("AMONGUS") a2 = A[int]() a2.shared_attr.a...
Opengraph URL: https://github.com/python/mypy/issues/11538
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"generic mutable class attributes introduce a vent in the type system","articleBody":"```py\r\nfrom typing import Generic, TypeVar\r\n\r\nT = TypeVar(\"T\")\r\n\r\n\r\nclass A(Generic[T]):\r\n shared_attr: list[T] = []\r\n\r\na1 = A[str]()\r\na1.shared_attr.append(\"AMONGUS\")\r\n\r\na2 = A[int]()\r\na2.shared_attr.append(1)\r\n\r\nvalue = a2.class_attr[0]\r\nreveal_type(value) # revealed type: int, actual value: AMONGUS\r\n```\r\n\r\nIn this example the shared attribute `shared_attr` is imposted upon by different instantiations of that class, causing a sus amongus to be appeared.","author":{"url":"https://github.com/KotlinIsland","@type":"Person","name":"KotlinIsland"},"datePublished":"2021-11-13T05:58:00Z","url":"https://github.com/python/mypy/issues/11538"}
| 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:6cd37b89-e58b-559e-ed48-45748ba904a4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9456:2046A4:1A62E1:23C667:6B002045 |
| html-safe-nonce | 71d29b4672ddef9cfff6beb1c3b967a9c289dc05ac25721a22f6d598a816a795 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NDU2OjIwNDZBNDoxQTYyRTE6MjNDNjY3OjZCMDAyMDQ1IiwidmlzaXRvcl9pZCI6IjY2Nzc3NjM4Njc0MTE0ODg4MzciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 55d1d29776ebaabf73883df27a639687a693539d1249509f4d6dcf1bd4f5e6ba |
| hovercard-subject-tag | issue:1052554337 |
| 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/11538/issue_layout |
| twitter:image | https://opengraph.githubassets.com/519bb55f711db991041a72f16af6d53c11e877454d38db4e7eb689504eabf4a6/python/mypy/issues/11538 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/519bb55f711db991041a72f16af6d53c11e877454d38db4e7eb689504eabf4a6/python/mypy/issues/11538 |
| og:image:alt | from typing import Generic, TypeVar T = TypeVar("T") class A(Generic[T]): shared_attr: list[T] = [] a1 = A[str]() a1.shared_attr.append("AMONGUS") a2 = A[int]() a2.shared_attr.append(1) value = a2.... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | KotlinIsland |
| 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