Whole file
tkem/cachetools
The author described this change as “Fix #163: Support user_function with cachetools.func decorators.”. It counts as a record because the checks below fail on the code as it stood at d6f962e80 and pass on 9a6cb65aa, with nothing else changed between the two runs.
Projecttkem/cachetools
Fix saved2020-04-08
Sharing licenceMIT · LICENSE
Change size+8 −0
What the code was meant to do, written into the code itself as a save note
Fix #163: Support user_function with cachetools.func decorators.
The change
| 93 | 93 | """ | |
| 94 | 94 | if maxsize is None: | |
| 95 | 95 | return _cache(_UnboundCache(), typed) | |
| 96 | + | elif callable(maxsize): | |
| 97 | + | return _cache(LFUCache(128), typed)(maxsize) | |
| 96 | 98 | else: | |
| 97 | 99 | return _cache(LFUCache(maxsize), typed) | |
| 98 | 100 | ||
| ⋯ | |||
| 105 | 107 | """ | |
| 106 | 108 | if maxsize is None: | |
| 107 | 109 | return _cache(_UnboundCache(), typed) | |
| 110 | + | elif callable(maxsize): | |
| 111 | + | return _cache(LRUCache(128), typed)(maxsize) | |
| 108 | 112 | else: | |
| 109 | 113 | return _cache(LRUCache(maxsize), typed) | |
| 110 | 114 | ||
| ⋯ | |||
| 117 | 121 | """ | |
| 118 | 122 | if maxsize is None: | |
| 119 | 123 | return _cache(_UnboundCache(), typed) | |
| 124 | + | elif callable(maxsize): | |
| 125 | + | return _cache(RRCache(128, choice), typed)(maxsize) | |
| 120 | 126 | else: | |
| 121 | 127 | return _cache(RRCache(maxsize, choice), typed) | |
| 122 | 128 | ||
| ⋯ | |||
| 128 | 134 | """ | |
| 129 | 135 | if maxsize is None: | |
| 130 | 136 | return _cache(_UnboundTTLCache(ttl, timer), typed) | |
| 137 | + | elif callable(maxsize): | |
| 138 | + | return _cache(TTLCache(128, ttl, timer), typed)(maxsize) | |
| 131 | 139 | else: | |
| 132 | 140 | return _cache(TTLCache(maxsize, ttl, timer), typed) | |
| 133 | 141 | ||
The check that tells the two apart
fail→pass·tests/test_func.py::LFUDecoratorTest::test_decorator_user_function
fail→pass·tests/test_func.py::LRUDecoratorTest::test_decorator_user_function
fail→pass·tests/test_func.py::RRDecoratorTest::test_decorator_user_function
fail→pass·tests/test_func.py::TTLDecoratorTest::test_decorator_user_function
Check file tests/test_func.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 itd6f962e80ed405756fb478bcb4165e85796371f9
Broken version dated2019-12-15
Modulecachetools.func
Units changedlfu_cache, lru_cache, rr_cache, ttl_cache
Fingerprint39e4951488e95187
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.