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.post0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 685337cada1eb68297e149e367da638de55504a665e4a300ac6dc10da7dbb4da |
|
MD5 | 6d45493105aa95a5b93f706f223f45c8 |
|
BLAKE2b-256 | e6ecf83995d36c267cedcf6d5058653705c67ab3edeb64a51281ad629ec15d06 |
Hashes for backports.cached_property-1.0.0.post0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33ee126a0b68e0019c87349fe4a880854a00c8b1ce092a1408578cf9fd585847 |
|
MD5 | e9c6b7917fc72f08dcc312234dd2a53a |
|
BLAKE2b-256 | f633ac3073905cd9211e20d35671a05f02a97b0df797b6588ee5bbf66aab77bb |