Title: ForwardRef: remove `__hash__` and `__eq__` · Issue #129463 · python/cpython · GitHub
Open Graph Title: ForwardRef: remove `__hash__` and `__eq__` · Issue #129463 · python/cpython
X Title: ForwardRef: remove `__hash__` and `__eq__` · Issue #129463 · python/cpython
Description: Feature or enhancement Currently, annotationlib.ForwardRef has a __hash__ and __eq__ method, which look at a few attributes: cpython/Lib/typing.py Line 1096 in 8b4a0d6 def __eq__(self, other): (3.13). These look unsound already; it's pos...
Open Graph Description: Feature or enhancement Currently, annotationlib.ForwardRef has a __hash__ and __eq__ method, which look at a few attributes: cpython/Lib/typing.py Line 1096 in 8b4a0d6 def __eq__(self, other): (3.1...
X Description: Feature or enhancement Currently, annotationlib.ForwardRef has a __hash__ and __eq__ method, which look at a few attributes: cpython/Lib/typing.py Line 1096 in 8b4a0d6 def __eq__(self, other): (3.1...
Opengraph URL: https://github.com/python/cpython/issues/129463
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"ForwardRef: remove `__hash__` and `__eq__`","articleBody":"# Feature or enhancement\n\nCurrently, `annotationlib.ForwardRef` has a `__hash__` and `__eq__` method, which look at a few attributes: https://github.com/python/cpython/blob/8b4a0d641cde667f94ce49f5e64da6bd9d6fbd9c/Lib/typing.py#L1096 (3.13). These look unsound already; it's possible for two ForwardRefs to compare equal but hash differently (if they have the same evaluated value but not the same `__forward_module__`). This gets worse on 3.14, where ForwardRef has gained a few more fields (https://github.com/python/cpython/blob/a4722449caccc42ad644611d02fbdb5005f601eb/Lib/annotationlib.py#L232).\n\nI think it's better to remove the `__eq__` and `__hash__` methods from `ForwardRef` objects, and make it so two ForwardRefs are equal only if they're identical. I don't see a good use case for comparing two ForwardRefs for equality; if you want to know that they refer to the same thing, you should evaluate them and compare the type object that comes out.\n\nThis came up in agronholm/typeguard#492 where the current implementation of equality caused some grief. cc people involved with some runtime type checking tools: @agronholm @Viicos @leycec.\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-129465\n* gh-132283\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/JelleZijlstra","@type":"Person","name":"JelleZijlstra"},"datePublished":"2025-01-30T04:50:05.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":6},"url":"https://github.com/129463/cpython/issues/129463"}
| 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:a24bf19b-7d70-24d8-a5fe-cb82ff819c23 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A986:10E844:92CD5B:C1E962:696B543D |
| html-safe-nonce | b5406ec82dbdc5a8a498aafa884c10fd427183a6aa355e8742ce42b030c55a1f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBOTg2OjEwRTg0NDo5MkNENUI6QzFFOTYyOjY5NkI1NDNEIiwidmlzaXRvcl9pZCI6IjY3MDM0OTMzNjcxODc4NTQzOTciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 9b7c946cf482d469dc2a73b320a91eb027cd78c9f474e64b1b386c3af0ba93fc |
| hovercard-subject-tag | issue:2819894484 |
| 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/cpython/129463/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e12b9543d58e09cfcad3d402e74aa507ca64bc5263d5105712439fc4faba2ef8/python/cpython/issues/129463 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e12b9543d58e09cfcad3d402e74aa507ca64bc5263d5105712439fc4faba2ef8/python/cpython/issues/129463 |
| og:image:alt | Feature or enhancement Currently, annotationlib.ForwardRef has a __hash__ and __eq__ method, which look at a few attributes: cpython/Lib/typing.py Line 1096 in 8b4a0d6 def __eq__(self, other): (3.1... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | JelleZijlstra |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5f99f7c1d70f01da5b93e5ca90303359738944d8ab470e396496262c66e60b8d |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| 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 | 82560a55c6b2054555076f46e683151ee28a19bc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width