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.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9306f9eed6ec55fd156ace6bc1094e2c86fae5fb2bf07b6a9c00745c656e75dd |
|
MD5 | 2de0257c18e50a8d189e93e8860aa674 |
|
BLAKE2b-256 | 08834cea5c665d2af765c02f7d8e8560b5918405c1d7d11ccfc60c4919c1cfd0 |
Hashes for backports.cached_property-1.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | baeb28e1cd619a3c9ab8941431fe34e8490861fb998c6c4590693d50171db0cc |
|
MD5 | 9b0a43c00e5bee52ddfc5d0677359d83 |
|
BLAKE2b-256 | ebae69e52acdcf381b108b36d989ea58656de4a9ab8863aba6176d80d01041df |