-
-
Notifications
You must be signed in to change notification settings - Fork 31k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-127750: Fix singledispatchmethod caching (v2) #128648
Open
eendebakpt
wants to merge
10
commits into
python:main
Choose a base branch
from
eendebakpt:singledispatchmethod_caching_v2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+59
−13
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b9a05dc
add singledispatchmethod test for objects with equal hash and ==
eendebakpt 0714c06
add singledispatchmethod test for dangling references
eendebakpt ef03f2d
use id for object cache in singledispatchmethod
eendebakpt 6c96b9d
📜🤖 Added by blurb_it.
blurb-it[bot] f282ab8
rework using __dict__
eendebakpt 89a4a5c
remove comments
eendebakpt ecc3e82
avoid exception
eendebakpt efd4034
whitespace
eendebakpt 88b5e90
whitespace
eendebakpt 1885278
Merge branch 'main' into singledispatchmethod_caching_v2
eendebakpt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
1 change: 1 addition & 0 deletions
1
Misc/NEWS.d/next/Library/2024-12-11-20-26-44.gh-issue-127750.8witaH.rst
This file contains 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 @@ | ||
Update caching of :class:`functools.singledispatchmethod` to avoid collisions of objects which compare equal. |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check
cached_property.__set_name__
, it has some more stuff in it - might be needed here as well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. The additions there prevent something like this:
The corresponding test for the
cached_property
for this iscpython/Lib/test/test_functools.py
Line 3315 in 34e840f
But on current main renaming is allowed for the singledispatchmethod.
I am not sure here what the desired behavior is (and why)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this implementation is desirable, maybe later someone who knows more about this can comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I know, the only reason cached properties can't be renamed is because the cache is keyed by the attribute's name.
Allowing a rebind would disconnect the cached property from it's cached value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I think you might want to either ignore renames or do something along these lines (ignoring error handling):
As far as I know, each binding shares the same instance of the descriptor, so as long as the cache key is constant, it should work no matter how many times it's been renamed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is kind of the same situation.
If rename is allowed, then it would simply cache to the last
attrname
. Drawback is that there is a small risk for unused cached methods.I think it might be most straight forward to copy+paste
cached_property.__set_name__
. It does seem a sensible restriction. It comes at expense of flexibility, but personally, I have never run into thatTypeError
.Also, it will be easier to address changes/improvements when 2 implementations that use the same caching approach are aligned.