Title: Generic propagation into dataclasses doesn't seem to work consistently · Issue #9585 · python/mypy · GitHub
Open Graph Title: Generic propagation into dataclasses doesn't seem to work consistently · Issue #9585 · python/mypy
X Title: Generic propagation into dataclasses doesn't seem to work consistently · Issue #9585 · python/mypy
Description: Optional static typing for Python. Contribute to python/mypy development by creating an account on GitHub.
Open Graph Description: Optional static typing for Python. Contribute to python/mypy development by creating an account on GitHub.
X Description: Optional static typing for Python. Contribute to python/mypy development by creating an account on GitHub.
Opengraph URL: https://github.com/python/mypy
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Generic propagation into dataclasses doesn't seem to work consistently","articleBody":"\u003c!--\r\n If you're new to mypy and you're not sure whether what you're experiencing is a mypy bug, please see the \"Question and Help\" form\r\n instead.\r\n-->\r\n\r\n**Bug Report**\r\n\r\nmypy doesn't seem to propagate generics into `dataclass`-generated methods correctly.\r\n\r\n**To Reproduce**\r\n\r\n```py\r\nfrom dataclasses import dataclass\r\nfrom typing import TypeVar, Generic, Dict, Any\r\n\r\nT = TypeVar(\"T\")\r\n\r\n\r\nclass FloatValue:\r\n pass\r\n\r\n\r\n@dataclass\r\nclass ValueByKey(Generic[T]):\r\n values: Dict[Any, T]\r\n\r\n\r\ndef foo(v: ValueByKey[FloatValue]):\r\n reveal_type(v.values)\r\n reveal_type(ValueByKey[FloatValue].__init__)\r\n```\r\n\r\n**Expected Behavior**\r\n\r\n```\r\n:; pipenv run mypy /tmp/footest.py\r\n/tmp/footest.py:17: note: Revealed type is 'builtins.dict[Any, footest.FloatValue*]'\r\n/tmp/footest.py:18: note: Revealed type is 'def (self: footest.ValueByKey[footest.FloatValue*], values: builtins.dict[Any, footest.FloatValue*])'\r\n```\r\n\r\n**Actual Behavior**\r\n\r\n```\r\n:; pipenv run mypy --version \r\nmypy 0.790\r\n:; pipenv run mypy /tmp/footest.py\r\n/tmp/footest.py:17: note: Revealed type is 'builtins.dict[Any, footest.FloatValue*]'\r\n/tmp/footest.py:18: note: Revealed type is 'def (self: footest.ValueByKey[T`1], values: builtins.dict[Any, T`1])'\r\n```\r\n\r\n**Your Environment**\r\n\r\n- Mypy version used: 0.790\r\n- Mypy command-line flags: see above\r\n- Mypy configuration options from `mypy.ini` (and other config files): none\r\n- Python version used: 3.7.8\r\n- Operating system and version: Arch Linux\r\n","author":{"url":"https://github.com/bdowning","@type":"Person","name":"bdowning"},"datePublished":"2020-10-12T19:17:36Z","url":"https://github.com/python/mypy/issues/9585"}
| 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 | /:user_id/:repository/issues/:id(.:format) |
| route-controller | issues |
| route-action | show |
| fetch-nonce | v2:99d804f2-f725-ba26-3fc0-eccceb89c757 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CEC0:3D9709:74174:9D4FF:6B0018F9 |
| html-safe-nonce | bf6a67c89816b096c722e9435ea97037c3aa64fe61b98fcca0659629126784b1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRUMwOjNEOTcwOTo3NDE3NDo5RDRGRjo2QjAwMThGOSIsInZpc2l0b3JfaWQiOiIyMTg4MzczMDA5NzYzNDA4MTIxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 13131109d68f408fd6afd9f0681fb9cb6ebd2e488a548733bc1d6c71569f8b15 |
| hovercard-subject-tag | repository:7053637 |
| 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/python/mypy/issues/9585 |
| twitter:image | https://opengraph.githubassets.com/f79ae5636353a0db17350af0a02700f2e9c3bbcf096f9450bf0c369c77cd1022/python/mypy |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f79ae5636353a0db17350af0a02700f2e9c3bbcf096f9450bf0c369c77cd1022/python/mypy |
| og:image:alt | Optional static typing for Python. Contribute to python/mypy development by creating an account on GitHub. |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | a2dd2291b1b13cc9c06f27ec92fa3dbaf34116fc24c9347b8539db61884c59f4 |
| turbo-cache-control | no-cache |
| 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 | 70121d4e855ee0bb7b75cf15d061d91f8863c0f8 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width