schrodinger :: infra :: util :: CreateWhenNeeded :: Class CreateWhenNeeded
[hide private]
[frames] | no frames]

Class CreateWhenNeeded

object --+
         |
        CreateWhenNeeded

This class can be used like property() (i.e., it is a descriptor; see section 3.3.2.2 in the python reference). It will hold off on creating the object until it is needed, but once it has been created it will return the object directly.

It's best used for attributes that are expensive to calculate (as measured by profiling, of course) and not always used.

Instance Methods [hide private]
 
__init__(self, function, name=None, doc=None)
Create the descriptor.
 
__get__(self, obj, cls)
Calculate the value from the function, then set the attribute of the object to this result and return it.

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, function, name=None, doc=None)
(Constructor)

 

Create the descriptor.

Overrides: object.__init__