pyiron_base.interfaces.lockable

pyiron_base.interfaces.lockable#

A small mixin to lock attribute and method access at runtime.

Sometimes we wish to restrict users of pyiron from changing certain things past certain stages of object lifetime, e.g. the input of jobs should only be changed before it is run, but still need to be able to change them internally. This can be implemented with Lockable and the decorator sentinel(). It should be thought of as a well defined escape hatch that is rarely necessary. Users should never be expected to unlock an object ever again after it has been locked by them or pyiron.

The context manager functionality is implemented in a separate class rather than directly on Lockable to conserve dunder name space real estate and let subclasses be context managers on their own.

Through out the code inside methods of Lockable will use object.__setattr__ and object.__getattribute__ to avoid any overloading attribute access that sibling classes may bring in.

Functions

sentinel(meth)

Wrap a method to fail if read_only is True on the owning object.

Classes

Lockable(*args[, lock_method])

A small mixin to lock attribute and method access at runtime.

Exceptions