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.

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

4848
4949 @property
5050 def cache_key(self):
51- return self.__key
51+ return functools.partial(self.__key, self._obj)
5252
5353 @property
5454 def cache_lock(self):
153153 cache = self.cache
154154 lock = self.cache_lock
155155 cond = self.cache_condition
156- key = self.cache_key(self._obj, *args, **kwargs)
156+ key = self.cache_key(*args, **kwargs)
157157
158158 with lock:
159159 cond.wait_for(lambda: key not in self.__pending)
199199 def __call__(self, *args, **kwargs):
200200 cache = self.cache
201201 lock = self.cache_lock
202- key = self.cache_key(self._obj, *args, **kwargs)
202+ key = self.cache_key(*args, **kwargs)
203203 with lock:
204204 try:
205205 result = cache[key]
238238
239239 def __call__(self, *args, **kwargs):
240240 cache = self.cache
241- key = self.cache_key(self._obj, *args, **kwargs)
241+ key = self.cache_key(*args, **kwargs)
242242 try:
243243 result = cache[key]
244244 self.__hits += 1

The check that tells the two apart

failpass·tests/test_cachedmethod.py::CacheMethodTest::test_decorator_attributes
failpass·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