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
gh-143831: Compare cells by identity in forward references#143848
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Uh oh!
There was an error while loading.Please reload this page.
This comment was marked as resolved.
This comment was marked as resolved.
johnslavik commentedJan 15, 2026 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Thank you for your interest in this! I encourage you to open a new issue if you think like the performance of Regarding why I solved it this way -- I just went with what the original intent was but with a corrected assumption about the hashability of cells. |
Uh oh!
There was an error while loading.Please reload this page.
JelleZijlstra commentedJan 15, 2026
If the performance of some part of the typing stack is a problem for you, please open a concise issue with concrete examples of what you would like to change. (Digressions on the beauty of the wilds of Canada are not necessary.) |
973643e to9f5f3c1Compare9f5f3c1 to6c36442Comparejohnslavik commentedJan 16, 2026 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I've considered simply basing things on the identity of |
Dict comprehensions are more readable and faster:❯ ./python -m timeit -s 'import types; c = dict(zip("abcdefghi", iter(types.CellType, None)))' 'dict(zip(c, map(id, c.values())))'100000 loops, best of 5: 3.15 usec per loop❯ ./python -m timeit -s 'import types; c = dict(zip("abcdefghi", iter(types.CellType, None)))' '{name: id(cell) for name, cell in c.items()}'100000 loops, best of 5: 2.86 usec per loopJelleZijlstra commentedJan 19, 2026
I don't know what's wrong with CI, I'll update the branch to see if it helps. |
59d3594 intopython:mainUh oh!
There was an error while loading.Please reload this page.
Thanks@johnslavik for the PR, and@JelleZijlstra for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14. |
…honGH-143848)(cherry picked from commit59d3594)Co-authored-by: Bartosz Sławecki <bartosz@ilikepython.com>
GH-144020 is a backport of this pull request to the3.14 branch. |
bedevere-bot commentedJan 19, 2026
|
Uh oh!
There was an error while loading.Please reload this page.
Cells are mutable and, in regular comparison, they are equal when their contents are equal (or if both are empty).
Two different cells should not be considered equal by value in forward references, though.
If there are two separate cells, they either (1) target different variables or (2) belong to different scopes, so two separate forward references storing two separate cells are conceptually unequal even if these cells happen to be equal at a given point in time. Mutability, essentially.
I'm still working on tests.✅TypeError: unhashable type: 'cell'#143831