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.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a5ef1e750f8bc7d0204c807aae8e0f450c655be0cf4b30407a35fd4bb27186c |
|
MD5 | 467e403f7c02d888e7af2647a6e18c9b |
|
BLAKE2b-256 | 4fd8fd7b8e24a207023e39b9c0cd607a9b3ba757552ec0d81b4328183961af2e |
Hashes for backports.cached_property-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 687b5fe14be40aadcf547cae91337a1fdb84026046a39370274e54d3fe4fb4f9 |
|
MD5 | 879c4101b5e8bbf7defd447afd17f6bb |
|
BLAKE2b-256 | d83277a2792d80c00083626e0d6ce41ba8254b632c960235d3a5a731c185d936 |