One function
_HashedTuple in tkem/cachetools
The author described this change as “Fix #130: Fix pickling/unpickling of cache keys.”. It counts as a record because the check below fails on the code as it stood at 3e5fe0227 and passes on 462e86795, with nothing else changed between the two runs.
Projecttkem/cachetools
Fix saved2019-05-20
Sharing licenceMIT · LICENSE
Change size+9 −0
What the code was meant to do, written into the code itself as a docstring
A tuple that ensures that hash() will be called no more than once per element, since cache decorators will hash the key multiple times on a cache miss. See also _HashedSeq in the standard library functools implementation.
The change
| 1 | 1 | class _HashedTuple(tuple): | |
| 2 | + | """A tuple that ensures that hash() will be called no more than once | |
| 3 | + | per element, since cache decorators will hash the key multiple | |
| 4 | + | times on a cache miss. See also _HashedSeq in the standard | |
| 5 | + | library functools implementation. | |
| 2 | 6 | ||
| 7 | + | """ | |
| 8 | + | ||
| 3 | 9 | __hashvalue = None | |
| 4 | 10 | ||
| 5 | 11 | def __hash__(self, hash=tuple.__hash__): | |
| ⋯ | |||
| 13 | 19 | ||
| 14 | 20 | def __radd__(self, other, add=tuple.__add__): | |
| 15 | 21 | return _HashedTuple(add(other, self)) | |
| 22 | + | ||
| 23 | + | def __getstate__(self): | |
| 24 | + | return {} | |
The check that tells the two apart
fail→pass·tests/test_keys.py::CacheKeysTest::test_pickle
Check file tests/test_keys.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 it3e5fe022716b0263488ef8146e18e162b2bcbe96
Broken version dated2019-05-20
Modulecachetools.keys
Units changed_HashedTuple
Fingerprinta7927020c3ccc952
Checked2026-08-17 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.