Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | 03-May-2022 | - | ||||
.idea/ | H | 04-Feb-2021 | - | 38 | 36 | |
backports/ | H | 04-Feb-2021 | - | 117 | 96 | |
backports.cached_property.egg-info/ | H | 03-May-2022 | - | 91 | 72 | |
.editorconfig | H A D | 04-Feb-2021 | 269 | 20 | 15 | |
.pydocstyle.ini | H A D | 04-Feb-2021 | 302 | 12 | 11 | |
LICENSE | H A D | 04-Feb-2021 | 1 KiB | 22 | 17 | |
MANIFEST.in | H A D | 04-Feb-2021 | 368 | 14 | 13 | |
PKG-INFO | H A D | 04-Feb-2021 | 4.1 KiB | 91 | 72 | |
README.rst | H A D | 04-Feb-2021 | 2.5 KiB | 65 | 47 | |
pyproject.toml | H A D | 04-Feb-2021 | 1.6 KiB | 68 | 51 | |
setup.cfg | H A D | 04-Feb-2021 | 815 | 64 | 53 | |
setup.py | H A D | 03-May-2022 | 2.8 KiB | 72 | 42 |
README.rst
1backports.cached_property 2========================= 3 4.. image:: https://travis-ci.com/penguinolog/backports.cached_property.svg?branch=master 5 :target: https://travis-ci.com/penguinolog/backports.cached_property 6.. image:: https://img.shields.io/pypi/v/backports.cached-property.svg 7 :target: https://pypi.python.org/pypi/backports.cached-property 8.. image:: https://img.shields.io/pypi/pyversions/backports.cached-property.svg 9 :target: https://pypi.python.org/pypi/backports.cached-property 10.. image:: https://img.shields.io/pypi/status/backports.cached-property.svg 11 :target: https://pypi.python.org/pypi/backports.cached-property 12.. image:: https://img.shields.io/github/license/penguinolog/backports.cached_property.svg 13 :target: https://raw.githubusercontent.com/penguinolog/backports.cached_property/master/LICENSE 14.. image:: https://img.shields.io/badge/code%20style-black-000000.svg 15 :target: https://github.com/ambv/black 16 17What 18---- 19 20Python 3.8 adds great descriptor to functools: cached_property. 21Technically all required APIs was available since python 3.6, 22but it is what it is. 23 24This package is a backport of this functionality for python 3.6 and 3.7. 25 26How to use 27---------- 28 29.. code-block:: python 30 31 from backports.cached_property import cached_property 32 33And then python 3.8 documentation will work (because code is minimally changed): 34 35.. class:: cached_property 36 37 Transform a method of a class into a property whose value is computed once 38 and then cached as a normal attribute for the life of the instance. Similar 39 to `property`, with the addition of caching. Useful for expensive 40 computed properties of instances that are otherwise effectively immutable. 41 42 Example:: 43 44 class DataSet: 45 def __init__(self, sequence_of_numbers): 46 self._data = sequence_of_numbers 47 48 @cached_property 49 def stdev(self): 50 return statistics.stdev(self._data) 51 52 @cached_property 53 def variance(self): 54 return statistics.variance(self._data) 55 56 57 .. note:: 58 59 This decorator requires that the ``__dict__`` attribute on each instance 60 be a mutable mapping. This means it will not work with some types, such as 61 metaclasses (since the ``__dict__`` attributes on type instances are 62 read-only proxies for the class namespace), and those that specify 63 ``__slots__`` without including ``__dict__`` as one of the defined slots 64 (as such classes don't provide a ``__dict__`` attribute at all). 65