- lsst.utils.classes.immutable(cls: _T) _T ¶
Decorate a class to simulate a simple form of immutability.
Subclasses of classes marked with
@immutableare also immutable.
Because this behavior interferes with the default implementation for the
immutableprovides implementations of
__setstate__that override this behavior. Immutable classes can then implement pickle via
Following the example of Python’s built-in immutable types, such as
immutabledecorator provides a
__copy__implementation that just returns
self, because there is no reason to actually copy an object if none of its shared owners can modify it.
Similarly, objects that are recursively (i.e. are themselves immutable and have only recursively immutable attributes) should also reimplement
self. This is not done by the decorator, as it has no way of checking for recursive immutability.