astropy 5.0

This essentially memorizes the value of the property by storing the result of its computation in the __dict__ of the object instance. This is useful for computing the value of some property that should otherwise be invariant. For example:

>>> class LazyTest:
...     @lazyproperty
...     def complicated_property(self):
...         print('Computing the value for complicated_property...')
...         return 42
...
>>> lt = LazyTest()
>>> lt.complicated_property
Computing the value for complicated_property...
42
>>> lt.complicated_property
42

As the example shows, the second time complicated_property is accessed, the print statement is not executed. Only the return value from the first access off complicated_property is returned.

By default, a setter and deleter are used which simply overwrite and delete, respectively, the value stored in __dict__ . Any user-specified setter or deleter is executed before executing these default actions. The one exception is that the default setter is not run if the user setter already sets the new value in __dict__ and returns that value and the returned value is not None .

Works similarly to property(), but computes the value only once.

Examples

See :

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /astropy/utils/decorators.py#729
type: <class 'type'>
Commit: