Lazy-Freeze: Another Look at Hashing and Immutability
summary
A technique is presented that makes objects turn immutable when their hash is first computed, implemented as a class decorator called lazy_freeze published on PyPI; it wraps attribute setters, delattr, __setitem__/__delitem__ and in‑place operators so numpy and container subclasses are protected, offers a debug mode that records the stacktrace of the hash call, and a frozen_attributes option to only lock fields used by a custom __hash__ implementation. The decorator works and the author used it to find a caching bug; threading still requires caution.
AI-written summary · about
