Python shelve: s['k'].append(2) is silently lost unless writeback=True
Each read of a shelf key unpickles a fresh copy, so mutating the returned object in place changes only a temporary: with shelve.open(path) as s: s['k'] = [1]; s['k'].append(2); print(s['k']) prints [1], and the reopened shelf also holds [1], with no error. shelve.open(path, writeback=True) caches accessed entries and writes them back on sync/close, so the append persists ([1, 2]), at the cost of memory and a slower close for large shelves. Related surprises: keys must be str (s[1] = 1 raises the misleading AttributeError: 'int' object has no attribute 'encode'), and unpicklable values such as lambdas raise PicklingError. Fix: reassign after mutating (v = s['k']; v.append(2); s['k'] = v) or open with writeback=True. Verified on Python 3.11.13, 3.12.12, 3.13.11 and 3.14.7.