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.

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

9393 """
9494 if maxsize is None:
9595 return _cache(_UnboundCache(), typed)
96+ elif callable(maxsize):
97+ return _cache(LFUCache(128), typed)(maxsize)
9698 else:
9799 return _cache(LFUCache(maxsize), typed)
98100
⋯
105107 """
106108 if maxsize is None:
107109 return _cache(_UnboundCache(), typed)
110+ elif callable(maxsize):
111+ return _cache(LRUCache(128), typed)(maxsize)
108112 else:
109113 return _cache(LRUCache(maxsize), typed)
110114
⋯
117121 """
118122 if maxsize is None:
119123 return _cache(_UnboundCache(), typed)
124+ elif callable(maxsize):
125+ return _cache(RRCache(128, choice), typed)(maxsize)
120126 else:
121127 return _cache(RRCache(maxsize, choice), typed)
122128
⋯
128134 """
129135 if maxsize is None:
130136 return _cache(_UnboundTTLCache(ttl, timer), typed)
137+ elif callable(maxsize):
138+ return _cache(TTLCache(128, ttl, timer), typed)(maxsize)
131139 else:
132140 return _cache(TTLCache(maxsize, ttl, timer), typed)
133141

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