Title: Special-casing `__hash__` · Issue #2284 · python/typing · GitHub
Open Graph Title: Special-casing `__hash__` · Issue #2284 · python/typing
X Title: Special-casing `__hash__` · Issue #2284 · python/typing
Description: The concept of "hashable" and "unhashable" classes has been a bit of the sore point in the past. typeshed uses __hash__: ClassVar[None] to mark classes as non-hashable, although that requires a # type: ignore[assignment] annotation. I th...
Open Graph Description: The concept of "hashable" and "unhashable" classes has been a bit of the sore point in the past. typeshed uses __hash__: ClassVar[None] to mark classes as non-hashable, although that requires a # t...
X Description: The concept of "hashable" and "unhashable" classes has been a bit of the sore point in the past. typeshed uses __hash__: ClassVar[None] to mark classes as non-hashable, although...
Opengraph URL: https://github.com/python/typing/issues/2284
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Special-casing `__hash__`","articleBody":"The concept of \"hashable\" and \"unhashable\" classes has been a bit of the sore point in the past. typeshed uses `__hash__: ClassVar[None]` to mark classes as non-hashable, although that requires a `# type: ignore[assignment]` annotation. I think this is special-cased by at least some type checkers for marking classes as unhashable.\n\nExcept for some wordage in the dataclasses section, the typing spec is silent about hashability. Since I believe that this needs special-casing by type checkers, it should be added to the typing spec. A raw idea:\n\n* Classes are hashable by default (due to `object.__hash__()` being implemented and typeshed having a type corresponding type annotation.)\n* To mark a class as non-hashable, use `__hash__: ClassVar[None]`. We could alternatively use something simpler such as `__hash__ = None`. I believe we used to use that, but I don't know why it's changed.\n* To mark a class as hashable, use `def __hash__(self, ...) -> ...`, usually `def __hash__(self) -> int: ...`.\n* Sub-classes inherit their parent's hashability, unless overridden.\n","author":{"url":"https://github.com/srittau","@type":"Person","name":"srittau"},"datePublished":"2026-05-12T14:03:25Z","url":"https://github.com/python/typing/issues/2284"}
| 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:16eb4ba1-856d-4eb5-2dc8-26286cb741f8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B4D8:2573D7:3A6510:4F9175:6AFF7D42 |
| html-safe-nonce | bb04805e9b703aea08a9cba702ec931143a4cbbe6d5498b73ceb0f2a0beff04c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNEQ4OjI1NzNENzozQTY1MTA6NEY5MTc1OjZBRkY3RDQyIiwidmlzaXRvcl9pZCI6IjExNjg0ODI5NDYwMDk0OTY4OTgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | b23a0af7fef973bf526179b9ef2c514c36742efc52ea6af9d321cfdce12f0e58 |
| hovercard-subject-tag | issue:4429773491 |
| 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/typing/2284/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7e9145b14422fc4f75e0b40222bc52cdddbc31dffbc52367fb11e7990cc262f6/python/typing/issues/2284 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7e9145b14422fc4f75e0b40222bc52cdddbc31dffbc52367fb11e7990cc262f6/python/typing/issues/2284 |
| og:image:alt | The concept of "hashable" and "unhashable" classes has been a bit of the sore point in the past. typeshed uses __hash__: ClassVar[None] to mark classes as non-hashable, although that requires a # t... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | srittau |
| hostname | github.com |
| expected-hostname | github.com |
| None | b5a2047dbbde77e0ba2f8dfd78621e8a7313a105f7437ca693fcccd16cd137ee |
| turbo-cache-control | no-preview |
| go-import | github.com/python/typing git https://github.com/python/typing.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 24604008 |
| octolytics-dimension-repository_nwo | python/typing |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24604008 |
| octolytics-dimension-repository_network_root_nwo | python/typing |
| 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 | 83e3dfa4de364d61589204ed35e53b2b7f77fba2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width