Title: dataclasses with generated __hash__ subclassing Hashable are considered abstract · Issue #18962 · python/mypy · GitHub
Open Graph Title: dataclasses with generated __hash__ subclassing Hashable are considered abstract · Issue #18962 · python/mypy
X Title: dataclasses with generated __hash__ subclassing Hashable are considered abstract · Issue #18962 · python/mypy
Description: Bug Report Dataclasses that are hashable (e.g. frozen=True) that extend any abc/protocol requiring __hash__ (e.g. collections.abc.Hashable) is considered abstract and gives an error when trying to be instantiated. In addition to frozen=T...
Open Graph Description: Bug Report Dataclasses that are hashable (e.g. frozen=True) that extend any abc/protocol requiring __hash__ (e.g. collections.abc.Hashable) is considered abstract and gives an error when trying to ...
X Description: Bug Report Dataclasses that are hashable (e.g. frozen=True) that extend any abc/protocol requiring __hash__ (e.g. collections.abc.Hashable) is considered abstract and gives an error when trying to ...
Opengraph URL: https://github.com/python/mypy/issues/18962
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"dataclasses with generated __hash__ subclassing Hashable are considered abstract","articleBody":"\u003c!--\nIf you're not sure whether what you're experiencing is a mypy bug, please see the \"Question and Help\" form instead.\nPlease consider:\n\n- checking our common issues page: https://mypy.readthedocs.io/en/stable/common_issues.html\n- searching our issue tracker: https://github.com/python/mypy/issues to see if it's already been reported\n- asking on gitter chat: https://gitter.im/python/typing\n-->\n\n**Bug Report**\n\n\u003c!--\nIf you're reporting a problem with a specific library function, the typeshed tracker is better suited for this report: https://github.com/python/typeshed/issues\n\nIf the project you encountered the issue in is open source, please provide a link to the project.\n-->\n\nDataclasses that are hashable (e.g. `frozen=True`) that extend any abc/protocol requiring `__hash__` (e.g. collections.abc.Hashable) is considered abstract and gives an error when trying to be instantiated.\n\nIn addition to `frozen=True`/`Hashable`, you also get the same error with `unsafe_hash=True`, as well as using your own protocol or abc that requires `__hash__`.\n\n**To Reproduce**\n\nhttps://mypy-play.net/?mypy=latest&python=3.12&gist=390504f01055e489b12b388eec1de256\n```python\nfrom dataclasses import dataclass\nfrom collections.abc import Hashable\n\n\n@dataclass(frozen=True)\nclass A:\n a: int\n\n\n@dataclass(frozen=True)\nclass B(Hashable):\n a: int\n\n\na: Hashable = A(1) # ok\nb = B(1) # error: Cannot instantiate abstract class \"A\" with abstract attribute \"__hash__\" [abstract]\n\nprint(hash(b)) # prints -6644214454873602895\n```\n\n**Expected Behavior**\n\nThis works at runtime -- running the script prints the hash, demonstrating that it has `__hash__` defined.\n\n**Actual Behavior**\n\n```\nmain.py:16: error: Cannot instantiate abstract class \"B\" with abstract attribute \"__hash__\" [abstract]\n```\n\n\u003c!-- What went wrong? Paste mypy's output. -->\n\n**Your Environment**\n\n\u003c!-- Include as many relevant details about the environment you experienced the bug in -->\n\n- Mypy version used: 1.15.0\n- Mypy command-line flags: N/A\n- Mypy configuration options from `mypy.ini` (and other config files): N/A\n- Python version used: 3.12\n\n\u003c!-- You can freely edit this text, please remove all the lines you believe are unnecessary. -->\n","author":{"url":"https://github.com/ralismark","@type":"Person","name":"ralismark"},"datePublished":"2025-04-24T10:37:12Z","url":"https://github.com/python/mypy/issues/18962"}
| 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:182caa85-fe0b-d12f-81ec-d7fef5b0ec5a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D824:5314B:2EE521A:3DF2B68:6B002877 |
| html-safe-nonce | 64f93780304a818d1b88d8e8962588b85c4f95fcf9fe160380da709bf2fc3446 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEODI0OjUzMTRCOjJFRTUyMUE6M0RGMkI2ODo2QjAwMjg3NyIsInZpc2l0b3JfaWQiOiIyMjE2NzA5NDM4NzUwODYxNDMxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | ef809a273a67a5d9ee5ab325daed0e9dbb06eaa31b3658f921cdd80c8580e7e7 |
| hovercard-subject-tag | issue:3016811678 |
| 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/18962/issue_layout |
| twitter:image | https://opengraph.githubassets.com/53b7b8df46d64a789966dd4da60baca6e04f53de23ac664640fd970d955a547a/python/mypy/issues/18962 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/53b7b8df46d64a789966dd4da60baca6e04f53de23ac664640fd970d955a547a/python/mypy/issues/18962 |
| og:image:alt | Bug Report Dataclasses that are hashable (e.g. frozen=True) that extend any abc/protocol requiring __hash__ (e.g. collections.abc.Hashable) is considered abstract and gives an error when trying to ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ralismark |
| 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