Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork34k
gh-143831: Compare cells by identity in forward references#143848
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
JelleZijlstra merged 14 commits intopython:mainfromjohnslavik:fix-forwardrefs-dont-hash-cellsJan 19, 2026
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
14 commits Select commitHold shift + click to select a range
55e07ae Hash and compare cells by identity
johnslavik9194bbf Merge branch 'main' into fix-forwardrefs-dont-hash-cells
johnslavikff81d6a Use appropriate semantics in `__eq__`
johnslavik6c36442 Add base test
johnslavikd8f5bc8 Test two paths
johnslavik348127f Simplify first self-test
johnslavikbc86ed2 Fix first self-test (typo)
johnslavikd434a40 Fix second self-test (typo)
johnslavik1f36f76 Add news entry
johnslavik32a3bef Re-run CI
johnslavik866aef1 Move self-tests to class level
johnslavik094f0f8 Fix typo in a test forwardref
johnslavik416c501 Use dict comprehensions instead of dict+zip
johnslavik4707033 Merge branch 'main' into fix-forwardrefs-dont-hash-cells
JelleZijlstraFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -279,7 +279,13 @@ def __eq__(self, other): | ||
| # because dictionaries are not hashable. | ||
| and self.__globals__ is other.__globals__ | ||
| and self.__forward_is_class__ == other.__forward_is_class__ | ||
| # Two separate cells are always considered unequal in forward refs. | ||
| and ( | ||
| {name: id(cell) for name, cell in self.__cell__.items()} | ||
| == {name: id(cell) for name, cell in other.__cell__.items()} | ||
| if isinstance(self.__cell__, dict) and isinstance(other.__cell__, dict) | ||
| else self.__cell__ is other.__cell__ | ||
| ) | ||
| and self.__owner__ == other.__owner__ | ||
| and ( | ||
| (tuple(sorted(self.__extra_names__.items())) if self.__extra_names__ else None) == | ||
| @@ -293,7 +299,10 @@ def __hash__(self): | ||
| self.__forward_module__, | ||
| id(self.__globals__), # dictionaries are not hashable, so hash by identity | ||
| self.__forward_is_class__, | ||
| ( # cells are not hashable as well | ||
| tuple(sorted([(name, id(cell)) for name, cell in self.__cell__.items()])) | ||
johnslavik marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| if isinstance(self.__cell__, dict) else id(self.__cell__), | ||
| ), | ||
| self.__owner__, | ||
| tuple(sorted(self.__extra_names__.items())) if self.__extra_names__ else None, | ||
| )) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletionsMisc/NEWS.d/next/Library/2026-01-16-06-22-10.gh-issue-143831.VLBTLp.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| :class:`annotationlib.ForwardRef` objects are now hashable when created from | ||
| annotation scopes with closures. Previously, hashing such objects would | ||
| throw an exception. Patch by Bartosz Sławecki. |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.