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.
Projecttkem/cachetools
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
| 8 | 8 | def decorator(method): | |
| 9 | 9 | def wrapper(self, *args, **kwargs): | |
| 10 | 10 | mapping = cache(self) | |
| 11 | + | if mapping is None: | |
| 12 | + | return method(self, *args, **kwargs) | |
| 11 | 13 | key = makekey((method,) + args, kwargs) | |
| 12 | 14 | try: | |
| 13 | 15 | return mapping[key] | |
| ⋯ | |||
| 17 | 19 | mapping[key] = result | |
| 18 | 20 | return result | |
| 19 | 21 | ||
| 22 | + | wrapper.cache = cache | |
| 20 | 23 | return functools.update_wrapper(wrapper, method) | |
| 21 | 24 | ||
| 22 | 25 | return decorator | |
The check that tells the two apart
fail→pass·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
- 2026-07-22TLRUCache
- 2026-03-08Fix #218: Fix and properly document @cachedmethod.cache_key handling.
- 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.