• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.idea/H04-Feb-2021-3836

backports/H04-Feb-2021-11796

backports.cached_property.egg-info/H03-May-2022-9172

.editorconfigH A D04-Feb-2021269 2015

.pydocstyle.iniH A D04-Feb-2021302 1211

LICENSEH A D04-Feb-20211 KiB2217

MANIFEST.inH A D04-Feb-2021368 1413

PKG-INFOH A D04-Feb-20214.1 KiB9172

README.rstH A D04-Feb-20212.5 KiB6547

pyproject.tomlH A D04-Feb-20211.6 KiB6851

setup.cfgH A D04-Feb-2021815 6453

setup.pyH A D03-May-20222.8 KiB7242

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