Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Conversation

@johnslavik
Copy link
Member

@johnslavikjohnslavik commentedJan 14, 2026
edited
Loading

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.

abhinand-c, Glinte, and leycec reacted with hooray emoji
@leycec

This comment was marked as resolved.

@johnslavik
Copy link
MemberAuthor

johnslavik commentedJan 15, 2026
edited
Loading

Thank you for your interest in this! I encourage you to open a new issue if you think like the performance ofForwardRef.__hash__ can and should be improved. I'm afraid it is out of scope of this surgical PR -- I will not be addressing anything outside the topic of cell comparison.


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.

cc@JelleZijlstra

abhinand-c reacted with thumbs up emoji

@JelleZijlstra
Copy link
Member

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.)

johnslavik reacted with thumbs up emoji

@johnslavikjohnslavikforce-pushed thefix-forwardrefs-dont-hash-cells branch 3 times, most recently from973643e to9f5f3c1CompareJanuary 16, 2026 05:04
@johnslavikjohnslavikforce-pushed thefix-forwardrefs-dont-hash-cells branch from9f5f3c1 to6c36442CompareJanuary 16, 2026 05:04
@johnslavikjohnslavik marked this pull request as ready for reviewJanuary 16, 2026 05:22
@johnslavik
Copy link
MemberAuthor

johnslavik commentedJan 16, 2026
edited
Loading

I've considered simply basing things on the identity of__cell__ (even as dict) but this wouldn't make sense because_build_closure creates a new dict object everytime. Two calls subsequent toget_annotations() on the same symbol should produce forward references that are fully equal; the current implementation is sound.

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 loop
@JelleZijlstra
Copy link
Member

I don't know what's wrong with CI, I'll update the branch to see if it helps.

@JelleZijlstraJelleZijlstra merged commit59d3594 intopython:mainJan 19, 2026
47 checks passed
@miss-islington-app
Copy link

Thanks@johnslavik for the PR, and@JelleZijlstra for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestJan 19, 2026
…honGH-143848)(cherry picked from commit59d3594)Co-authored-by: Bartosz Sławecki <bartosz@ilikepython.com>
@bedevere-app
Copy link

GH-144020 is a backport of this pull request to the3.14 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.14bugs and security fixes labelJan 19, 2026
JelleZijlstra pushed a commit that referenced this pull requestJan 19, 2026
…-143848) (#144020)gh-143831: Compare cells by identity in forward references (GH-143848)(cherry picked from commit59d3594)Co-authored-by: Bartosz Sławecki <bartosz@ilikepython.com>
@bedevere-bot
Copy link

⚠️⚠️⚠️ Buildbot failure⚠️⚠️⚠️

Hi! The buildbotARM64 macOS 3.14 (tier-2) has failed when building commit2147d3f.

What do you need to do:

  1. Don't panic.
  2. Checkthe buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1772/builds/817) and take a look at the build logs.
  4. Check if the failure is related to this commit (2147d3f) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/1772/builds/817

Failed tests:

  • test_urllib2net

Summary of the results of the build (if available):

==

Click to see traceback logs
remote:Enumerating objects: 11, done.remote:Counting objects:  10% (1/10)remote:Counting objects:  20% (2/10)remote:Counting objects:  30% (3/10)remote:Counting objects:  40% (4/10)remote:Counting objects:  50% (5/10)remote:Counting objects:  60% (6/10)remote:Counting objects:  70% (7/10)remote:Counting objects:  80% (8/10)remote:Counting objects:  90% (9/10)remote:Counting objects: 100% (10/10)remote:Counting objects: 100% (10/10), done.remote:Compressing objects:  33% (1/3)remote:Compressing objects:  66% (2/3)remote:Compressing objects: 100% (3/3)remote:Compressing objects: 100% (3/3), done.remote:Total 11 (delta 7), reused 7 (delta 7), pack-reused 1 (from 1)From https://github.com/python/cpython * branch                    3.14       -> FETCH_HEADNote:switching to '2147d3fa2b25e390462e859abb4d791ce07496c7'.You are in 'detached HEAD' state. You can look around, make experimentalchanges and commit them, and you can discard any commits you make in thisstate without impacting any branches by switching back to a branch.If you want to create a new branch to retain commits you create, you maydo so (now or later) by using -c with the switch command. Example:  git switch -c <new-branch-name>Or undo this operation with:  git switch -Turn off this advice by setting config variable advice.detachedHead to falseHEAD is now at 2147d3fa2b2 [3.14] gh-143831: Compare cells by identity in forward references (GH-143848) (#144020)Switched to and reset branch '3.14'make:*** [buildbottest] Error 2
johnslavik reacted with thumbs down emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@JelleZijlstraJelleZijlstraJelleZijlstra approved these changes

+1 more reviewer

@abhinand-cabhinand-cabhinand-c left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

5 participants

@johnslavik@leycec@JelleZijlstra@bedevere-bot@abhinand-c

[8]ページ先頭

©2009-2026 Movatter.jp