Title: Mypy treating type of final class variable in dataclass as Any · Issue #21906 · python/mypy · GitHub
Open Graph Title: Mypy treating type of final class variable in dataclass as Any · Issue #21906 · python/mypy
X Title: Mypy treating type of final class variable in dataclass as Any · Issue #21906 · python/mypy
Description: Bug Report from dataclasses import dataclass from typing import ClassVar, Final, reveal_type class Bar: pass @dataclass class Foo: cv: ClassVar[Final[dict[type[Bar], Foo]]] = {} reveal_type(Foo.cv) $ mypy test.py test.py:10: note: Reveal...
Open Graph Description: Bug Report from dataclasses import dataclass from typing import ClassVar, Final, reveal_type class Bar: pass @dataclass class Foo: cv: ClassVar[Final[dict[type[Bar], Foo]]] = {} reveal_type(Foo.cv)...
X Description: Bug Report from dataclasses import dataclass from typing import ClassVar, Final, reveal_type class Bar: pass @dataclass class Foo: cv: ClassVar[Final[dict[type[Bar], Foo]]] = {} reveal_type(Foo.cv)...
Opengraph URL: https://github.com/python/mypy/issues/21906
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Mypy treating type of final class variable in dataclass as Any","articleBody":"**Bug Report**\n\n```python\nfrom dataclasses import dataclass\nfrom typing import ClassVar, Final, reveal_type\n\nclass Bar: pass\n\n@dataclass\nclass Foo:\n cv: ClassVar[Final[dict[type[Bar], Foo]]] = {}\n\nreveal_type(Foo.cv)\n```\n\n```\n$ mypy test.py\ntest.py:10: note: Revealed type is \"Any\"\nSuccess: no issues found in 1 source file\n```\n\nThe correct type of `Foo.cv` is `builtins.dict[type[Bar], Foo]`.\n\n**To Reproduce**\n\nhttps://mypy-play.net/?mypy=latest&python=3.14&gist=2fad4ef5fded90ecaeb0f1d1e59d882a\n\n**Expected Behavior**\n\n`reveal_type` should report the correct type for the class variable.\n\n**Actual Behavior**\n\n`reveal_type` showed incorrect type (`Any`).\n\n**Your Environment**\n\n* Fedora 44\n* `python3-mypy-1.18.2-4.fc44.noarch` (reproducible with Mypy 2.3.1)\n* `python3-3.14.6-1.fc44.x86_64`\n* No config files used","author":{"url":"https://github.com/ipilcher","@type":"Person","name":"ipilcher"},"datePublished":"2026-08-28T18:02:56Z","url":"https://github.com/python/mypy/issues/21906"}
| 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:32e6a5aa-44fe-f75b-4abb-e17c39daa82a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9CA8:3CBF1A:8505D5:B3C0C9:6AFF990F |
| html-safe-nonce | aaa8b043da250c2ccd48c9dd198bf24bb4937a44f0f28dfd2c80cfcaea9017cc |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5Q0E4OjNDQkYxQTo4NTA1RDU6QjNDMEM5OjZBRkY5OTBGIiwidmlzaXRvcl9pZCI6IjQxNTM5NzYyNjAzNDA0NTU2OTUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 61b0227e00ac81694d1f11d0fd562ac41ca6956540166b361dc4dfcf54dd566c |
| hovercard-subject-tag | issue:5280936293 |
| 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/21906/issue_layout |
| twitter:image | https://opengraph.githubassets.com/93b0692922423450ccae79014caa73b0f92f534308ba387e00afdd7104f66f62/python/mypy/issues/21906 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/93b0692922423450ccae79014caa73b0f92f534308ba387e00afdd7104f66f62/python/mypy/issues/21906 |
| og:image:alt | Bug Report from dataclasses import dataclass from typing import ClassVar, Final, reveal_type class Bar: pass @dataclass class Foo: cv: ClassVar[Final[dict[type[Bar], Foo]]] = {} reveal_type(Foo.cv)... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ipilcher |
| hostname | github.com |
| expected-hostname | github.com |
| None | 2c75d045e8c84b51e2ac680086a6dd1eeaf2bc15b82137d22ee5106835d6256c |
| 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 | 525b66d22c4f7e6bb8b62934bec198964f7e8b93 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width