immutable

lsst.daf.butler.core.utils.immutable(cls: Type[CT_co]) → Type[CT_co]

A class decorator that simulates a simple form of immutability for the decorated class.

A class decorated as immutable may only set each of its attributes once (by convention, in __new__); any attempts to set an already-set attribute will raise AttributeError.

Because this behavior interferes with the default implementation for the pickle and copy modules, immutable provides implementations of __getstate__ and __setstate__ that override this behavior. Immutable classes can them implement pickle/copy via __getnewargs__ only (other approaches such as __reduce__ and __deepcopy__ may also be used).