One function

cachedmethod in tkem/cachetools

The author described this change as Fix #15: Allow @cachedmethod.cache() to return None. It counts as a record because the check below fails on the code as it stood at cb95c354c and passes on 430e338e3, with nothing else changed between the two runs.

Fix saved2014-10-23
Sharing licenceMIT · LICENSE
Change size+3 0

What the code was meant to do, written into the code itself as a docstring

Decorator to wrap a class or instance method with a memoizing callable that saves results in a (possibly shared) cache.

The change

88 def decorator(method):
99 def wrapper(self, *args, **kwargs):
1010 mapping = cache(self)
11+ if mapping is None:
12+ return method(self, *args, **kwargs)
1113 key = makekey((method,) + args, kwargs)
1214 try:
1315 return mapping[key]
1719 mapping[key] = result
1820 return result
1921
22+ wrapper.cache = cache
2023 return functools.update_wrapper(wrapper, method)
2124
2225 return decorator

The check that tells the two apart

failpass·tests/test_cachedmethod.py::CachedMethodTest::test_decorator

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 itcb95c354cee3ac998a0ccd0e264a5851d8b1d161
Broken version dated2014-10-23
Modulecachetools.decorators
Units changedcachedmethod
Fingerprinte2a3c807695fba4a
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