Descriptor support for NIPY.
Utilities to support special Python descriptors ([R3], [R4]), 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.
[R3] | How-To Guide for Descriptors, Raymond |
Hettinger. http://users.rcn.com/python/download/Descriptor.htm
[R4] | Python data model, http://docs.python.org/reference/datamodel.html |
A descriptor to make special properties that become normal attributes.
Decorator to create OneTimeProperty attributes.
Parameters : | func : method
|
---|
Examples
>>> class MagicProp(object):
... @setattr_on_read
... def a(self):
... return 99
...
>>> x = MagicProp()
>>> 'a' in x.__dict__
False
>>> x.a
99
>>> 'a' in x.__dict__
True