Title: Incorrect inference for types with `__eq__` and no `__hash__` · Issue #18622 · python/mypy · GitHub
Open Graph Title: Incorrect inference for types with `__eq__` and no `__hash__` · Issue #18622 · python/mypy
X Title: Incorrect inference for types with `__eq__` and no `__hash__` · Issue #18622 · python/mypy
Description: problem class A: def __eq__(self, o: object, /) -> bool: return self is o reveal_type(A().__hash__) # def () -> builtins.int https://mypy-play.net/?mypy=latest&python=3.13&flags=strict,local-partial-types&gist=2b23624b1df772175b70c08e3...
Open Graph Description: problem class A: def __eq__(self, o: object, /) -> bool: return self is o reveal_type(A().__hash__) # def () -> builtins.int https://mypy-play.net/?mypy=latest&python=3.13&flags=strict,local-part...
X Description: problem class A: def __eq__(self, o: object, /) -> bool: return self is o reveal_type(A().__hash__) # def () -> builtins.int https://mypy-play.net/?mypy=latest&python=3.13&flags=stric...
Opengraph URL: https://github.com/python/mypy/issues/18622
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Incorrect inference for types with `__eq__` and no `__hash__`","articleBody":"# problem\n\n```py\nclass A:\n def __eq__(self, o: object, /) -> bool:\n return self is o\n\nreveal_type(A().__hash__) # def () -> builtins.int\n```\n\nhttps://mypy-play.net/?mypy=latest&python=3.13&flags=strict%2Clocal-partial-types&gist=2b23624b1df772175b70c08e36a6e912\n\nyet \n\n```pycon\n>>> class A:\n... def __eq__(self, o: object, /) -> bool:\n... return self is o\n... \n>>> type(A.__hash__)\n\u003cclass 'NoneType'>\n```\n\n# solution\n\niff. class `A`, and only class `A` (i.e. excluding any base classes)\n\n- implements `__eq__`, and \n- does not implement `__hash__`\n\ninfer `A.__hash__: ClassVar[None]` \n","author":{"url":"https://github.com/jorenham","@type":"Person","name":"jorenham"},"datePublished":"2025-02-06T18:57:15Z","url":"https://github.com/python/mypy/issues/18622"}
| 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:63747540-6dee-ad91-55ee-0641adbb3442 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E514:1A1C04:1CA49E7:26EA120:6B000BA9 |
| html-safe-nonce | c78f7a267f230f753f81d4409177ce2aa7e51cdb995160146a151a5cc0475aef |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNTE0OjFBMUMwNDoxQ0E0OUU3OjI2RUExMjA6NkIwMDBCQTkiLCJ2aXNpdG9yX2lkIjoiNDY3MjM3OTMwNjg4ODkyNDA3MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | a9b0efdd1d5212d12ebba6c4dc20341d874265862910cb68d8c0a3af2875c61d |
| hovercard-subject-tag | issue:2836339424 |
| 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/18622/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1bf48c193be3f31703c6bc222453d0c29638ba892c43d9c27f9b8c939692806f/python/mypy/issues/18622 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1bf48c193be3f31703c6bc222453d0c29638ba892c43d9c27f9b8c939692806f/python/mypy/issues/18622 |
| og:image:alt | problem class A: def __eq__(self, o: object, /) -> bool: return self is o reveal_type(A().__hash__) # def () -> builtins.int https://mypy-play.net/?mypy=latest&python=3.13&flags=strict,local-part... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jorenham |
| hostname | github.com |
| expected-hostname | github.com |
| None | 0a0d8686a27478df474dd7415776a7a080cde8838b3cd92ea7601187572e5729 |
| 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 | 16a11879678aaf97e2a42c33ee70830aa084fa37 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width