Whole file
tkem/cachetools
The author described this change as “Fix #218: Fix and properly document @cachedmethod.cache_key handling.”. It counts as a record because the checks below fail on the code as it stood at 98ec79ff8 and pass on 18e5930ce, with nothing else changed between the two runs.
Projecttkem/cachetools
Fix saved2026-03-08
Sharing licenceMIT · LICENSE
Change size+4 −4
What the code was meant to do, written into the code itself as a save note
Fix #218: Fix and properly document @cachedmethod.cache_key handling.
The change
| 48 | 48 | ||
| 49 | 49 | @property | |
| 50 | 50 | def cache_key(self): | |
| 51 | - | return self.__key | |
| 51 | + | return functools.partial(self.__key, self._obj) | |
| 52 | 52 | ||
| 53 | 53 | @property | |
| 54 | 54 | def cache_lock(self): | |
| ⋯ | |||
| 153 | 153 | cache = self.cache | |
| 154 | 154 | lock = self.cache_lock | |
| 155 | 155 | cond = self.cache_condition | |
| 156 | - | key = self.cache_key(self._obj, *args, **kwargs) | |
| 156 | + | key = self.cache_key(*args, **kwargs) | |
| 157 | 157 | ||
| 158 | 158 | with lock: | |
| 159 | 159 | cond.wait_for(lambda: key not in self.__pending) | |
| ⋯ | |||
| 199 | 199 | def __call__(self, *args, **kwargs): | |
| 200 | 200 | cache = self.cache | |
| 201 | 201 | lock = self.cache_lock | |
| 202 | - | key = self.cache_key(self._obj, *args, **kwargs) | |
| 202 | + | key = self.cache_key(*args, **kwargs) | |
| 203 | 203 | with lock: | |
| 204 | 204 | try: | |
| 205 | 205 | result = cache[key] | |
| ⋯ | |||
| 238 | 238 | ||
| 239 | 239 | def __call__(self, *args, **kwargs): | |
| 240 | 240 | cache = self.cache | |
| 241 | - | key = self.cache_key(self._obj, *args, **kwargs) | |
| 241 | + | key = self.cache_key(*args, **kwargs) | |
| 242 | 242 | try: | |
| 243 | 243 | result = cache[key] | |
| 244 | 244 | self.__hits += 1 | |
The check that tells the two apart
fail→pass·tests/test_cachedmethod.py::CacheMethodTest::test_decorator_attributes
fail→pass·tests/test_cachedmethod.py::DictMethodTest::test_decorator_attributes
Check file tests/test_cachedmethod.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before it98ec79ff8be24ce1346d6a96602f11ccbda4f76f
Broken version dated2026-03-08
Modulecachetools._cachedmethod
Units changed_WrapperBase, _condition_info, _locked_info, _unlocked_info
Fingerprint5ee02972be299b15
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.
Other bugs found in tkem/cachetools
- 2026-07-22TLRUCache
- 2026-03-05_DescriptorBase
- 2024-08-18Fix #292, fix #205, fix #103: TTLCache.expire() returns iterable of expired (key, value) pairs.
- 2024-07-15mru_cache
- 2021-12-21Fix #159: Pass self to @cachedmethod key function.
- 2021-12-18TTLCache