Repository navigation
Normalize cachedmethod keys for unbound calls - #541
Closed
theman6660 wants to merge 1 commit into
Closed
theman6660 wants to merge 1 commit into
theman6660 wants to merge 1 commit into
Conversation
Owner
|
Folded into #609 (see the PR description for credit). Thanks for the report and the repro. |
blebo
pushed a commit
to blebo/boltons
that referenced
this pull request
Nov 1, 2026
…|=, eq, ThresholdCounter width (mahmoud#498, mahmoud#593, mahmoud#541, mahmoud#506, mahmoud#490, mahmoud#580, mahmoud#598)
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The change
obj.method(3)andClass.method(obj, 3)generate different cache keys for the same cached method. Calling both currently runs the method twice and stores two entries. Withscoped=False, an unbound call also includes the instance in the key, so unhashable instances fail even though the equivalent bound call succeeds.Separate the receiver from the arguments before building either form's key. Use
(obj, func)only when scoped, and always pass the receiver when invoking the underlying function. Bound-call keys stay unchanged, and unbound calls reuse them. Existing custom key functions receive the same normalized arguments for both invocation forms.Regression coverage checks both call orders, attribute/callable/mapping caches, scoped and typed configurations, keyword arguments, unhashable unscoped receivers, custom key callbacks, instance isolation/sharing, and numeric type distinctions.
Validation on Windows / Python 3.12.10:
git diff --check: passed.Other interpreter versions and operating systems were not tested locally.
The backstory
Previous contribution: #519, which includes my contribution background. This was found while comparing bound and unbound calls during a source inspection for small, verifiable contributions, rather than from a production incident.
AI assistance