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.

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

11 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.
26
7+ """
8+
39 __hashvalue = None
410
511 def __hash__(self, hash=tuple.__hash__):
1319
1420 def __radd__(self, other, add=tuple.__add__):
1521 return _HashedTuple(add(other, self))
22+
23+ def __getstate__(self):
24+ return {}

The check that tells the two apart

failpass·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