backports.cached_property
=========================
.. image:: https://travis-ci.com/penguinolog/backports.cached_property.svg?branch=master
:target: https://travis-ci.com/penguinolog/backports.cached_property
.. image:: https://img.shields.io/pypi/v/backports.cached-property.svg
:target: https://pypi.python.org/pypi/backports.cached-property
.. image:: https://img.shields.io/pypi/pyversions/backports.cached-property.svg
:target: https://pypi.python.org/pypi/backports.cached-property
.. image:: https://img.shields.io/pypi/status/backports.cached-property.svg
:target: https://pypi.python.org/pypi/backports.cached-property
.. image:: https://img.shields.io/github/license/penguinolog/backports.cached_property.svg
:target: https://raw.githubusercontent.com/penguinolog/backports.cached_property/master/LICENSE
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/ambv/black
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
----------
.. code-block:: python
from backports.cached_property import cached_property
And then python 3.8 documentation will work (because code is minimally changed):
.. class:: cached_property
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)
.. note::
This decorator requires that the ``__dict__`` attribute on each instance
be a mutable mapping. This means it will not work with some types, such as
metaclasses (since the ``__dict__`` attributes on type instances are
read-only proxies for the class namespace), and those that specify
``__slots__`` without including ``__dict__`` as one of the defined slots
(as such classes don't provide a ``__dict__`` attribute at all).
Raw data
{
"_id": null,
"home_page": "https://github.com/penguinolog/backports.cached_property",
"name": "backports.cached-property",
"maintainer": "Aleksei Stepanov penguinolog@gmail.com",
"docs_url": null,
"requires_python": ">=3.6.0",
"maintainer_email": "",
"keywords": "caching,development",
"author": "Aleksei Stepanov",
"author_email": "penguinolog@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/08/83/4cea5c665d2af765c02f7d8e8560b5918405c1d7d11ccfc60c4919c1cfd0/backports.cached-property-1.0.2.tar.gz",
"platform": null,
"description": "backports.cached_property\n=========================\n\n.. image:: https://travis-ci.com/penguinolog/backports.cached_property.svg?branch=master\n :target: https://travis-ci.com/penguinolog/backports.cached_property\n.. image:: https://img.shields.io/pypi/v/backports.cached-property.svg\n :target: https://pypi.python.org/pypi/backports.cached-property\n.. image:: https://img.shields.io/pypi/pyversions/backports.cached-property.svg\n :target: https://pypi.python.org/pypi/backports.cached-property\n.. image:: https://img.shields.io/pypi/status/backports.cached-property.svg\n :target: https://pypi.python.org/pypi/backports.cached-property\n.. image:: https://img.shields.io/github/license/penguinolog/backports.cached_property.svg\n :target: https://raw.githubusercontent.com/penguinolog/backports.cached_property/master/LICENSE\n.. image:: https://img.shields.io/badge/code%20style-black-000000.svg\n :target: https://github.com/ambv/black\n\nWhat\n----\n\nPython 3.8 adds great descriptor to functools: cached_property.\nTechnically all required APIs was available since python 3.6,\nbut it is what it is.\n\nThis package is a backport of this functionality for python 3.6 and 3.7.\n\nHow to use\n----------\n\n.. code-block:: python\n\n from backports.cached_property import cached_property\n\nAnd then python 3.8 documentation will work (because code is minimally changed):\n\n.. class:: cached_property\n\n Transform a method of a class into a property whose value is computed once\n and then cached as a normal attribute for the life of the instance. Similar\n to `property`, with the addition of caching. Useful for expensive\n computed properties of instances that are otherwise effectively immutable.\n\n Example::\n\n class DataSet:\n def __init__(self, sequence_of_numbers):\n self._data = sequence_of_numbers\n\n @cached_property\n def stdev(self):\n return statistics.stdev(self._data)\n\n @cached_property\n def variance(self):\n return statistics.variance(self._data)\n\n\n .. note::\n\n This decorator requires that the ``__dict__`` attribute on each instance\n be a mutable mapping. This means it will not work with some types, such as\n metaclasses (since the ``__dict__`` attributes on type instances are\n read-only proxies for the class namespace), and those that specify\n ``__slots__`` without including ``__dict__`` as one of the defined slots\n (as such classes don't provide a ``__dict__`` attribute at all).\n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "cached_property() - computed once per instance, cached as attribute",
"version": "1.0.2",
"project_urls": {
"Bug Tracker": "https://github.com/penguinolog/backports.cached_property/issues",
"Homepage": "https://github.com/penguinolog/backports.cached_property"
},
"split_keywords": [
"caching",
"development"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "ebae69e52acdcf381b108b36d989ea58656de4a9ab8863aba6176d80d01041df",
"md5": "9b0a43c00e5bee52ddfc5d0677359d83",
"sha256": "baeb28e1cd619a3c9ab8941431fe34e8490861fb998c6c4590693d50171db0cc"
},
"downloads": -1,
"filename": "backports.cached_property-1.0.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "9b0a43c00e5bee52ddfc5d0677359d83",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6.0",
"size": 6090,
"upload_time": "2022-06-14T08:48:16",
"upload_time_iso_8601": "2022-06-14T08:48:16.734234Z",
"url": "https://files.pythonhosted.org/packages/eb/ae/69e52acdcf381b108b36d989ea58656de4a9ab8863aba6176d80d01041df/backports.cached_property-1.0.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "08834cea5c665d2af765c02f7d8e8560b5918405c1d7d11ccfc60c4919c1cfd0",
"md5": "2de0257c18e50a8d189e93e8860aa674",
"sha256": "9306f9eed6ec55fd156ace6bc1094e2c86fae5fb2bf07b6a9c00745c656e75dd"
},
"downloads": -1,
"filename": "backports.cached-property-1.0.2.tar.gz",
"has_sig": false,
"md5_digest": "2de0257c18e50a8d189e93e8860aa674",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6.0",
"size": 8031,
"upload_time": "2022-06-14T08:48:18",
"upload_time_iso_8601": "2022-06-14T08:48:18.937747Z",
"url": "https://files.pythonhosted.org/packages/08/83/4cea5c665d2af765c02f7d8e8560b5918405c1d7d11ccfc60c4919c1cfd0/backports.cached-property-1.0.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2022-06-14 08:48:18",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "penguinolog",
"github_project": "backports.cached_property",
"travis_ci": true,
"coveralls": false,
"github_actions": true,
"requirements": [],
"tox": true,
"lcname": "backports.cached-property"
}