nibabel.onetime

Descriptor support for NIPY.

Utilities to support special Python descriptors [1,2], in particular the use of a useful pattern for properties we call ‘one time properties’. These are object attributes which are declared as properties, but become regular attributes once they’ve been read the first time. They can thus be evaluated later in the object’s life cycle, but once evaluated they become normal, static attributes with no function call overhead on access or any other constraints.

A special ResetMixin class is provided to add a .reset() method to users who may want to have their objects capable of resetting these computed properties to their ‘untriggered’ state.

References

[1] How-To Guide for Descriptors, Raymond Hettinger. https://docs.python.org/howto/descriptor.html

[2] Python data model, https://docs.python.org/reference/datamodel.html

Functions

auto_attr(func)

Decorator to create OneTimeProperty attributes.

setattr_on_read(func)

Decorator to create OneTimeProperty attributes.

Classes

OneTimeProperty(func)

A descriptor to make special properties that become normal attributes.

ResetMixin()

A Mixin class to add a .reset() method to users of OneTimeProperty.