immutable¶
-
lsst.daf.butler.core.utils.
immutable
(cls)¶ 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 raiseAttributeError
.Because this behavior interferes with the default implementation for the
pickle
andcopy
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).