cached_property() - computed once per instance, cached as attribute
Project description
What
Python 3.8 adds great descriptor to functools: cached_property. Technically all required APIs was available since python 3.6, but it is what it is.
This package is a backport of this functionality for python 3.6 and 3.7.
How to use
from backports.cached_property import cached_property
And then python 3.8 documentation will work (because code is minimally changed):
Transform a method of a class into a property whose value is computed once and then cached as a normal attribute for the life of the instance. Similar to property, with the addition of caching. Useful for expensive computed properties of instances that are otherwise effectively immutable.
Example:
class DataSet: def __init__(self, sequence_of_numbers): self._data = sequence_of_numbers @cached_property def stdev(self): return statistics.stdev(self._data) @cached_property def variance(self): return statistics.variance(self._data)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for backports.cached-property-1.0.0.post2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74d525451ff39a069701ed81247e708498a387eeb35043070d008e1c25ed1b0c |
|
MD5 | d69f14ee5eefeb92190f36db9cbebeff |
|
BLAKE2b-256 | e8f6a5fdf81808e48b202afe3d8be62ca5879acd64a9f44763789dcfb983a1fd |
Hashes for backports.cached_property-1.0.0.post2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 268eb9a5c6bb74d567038d574d7c2abfdadb481522ed8c5f230c13a898472673 |
|
MD5 | 1a8249498e939c335f071168c2d26a56 |
|
BLAKE2b-256 | e93dc2abcd66048d3b7272858b0be7a65b6d220f541c73c9a82007e56f7f8510 |