Skip to content

Commit

Permalink
pythongh-104112: link from cached_property docs to method-caching FAQ (
Browse files Browse the repository at this point in the history
…pythonGH-104113)

(cherry picked from commit fa86a77)

Co-authored-by: Carl Meyer <carl@oddbird.net>
Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
  • Loading branch information
2 people authored and miss-islington committed May 4, 2023
1 parent 6a970ae commit 0271e1c
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions Doc/library/functools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,10 @@ The :mod:`functools` module defines the following functions:
``__slots__`` without including ``__dict__`` as one of the defined slots
(as such classes don't provide a ``__dict__`` attribute at all).

If a mutable mapping is not available or if space-efficient key sharing
is desired, an effect similar to :func:`cached_property` can be achieved
by a stacking :func:`property` on top of :func:`cache`::

class DataSet:
def __init__(self, sequence_of_numbers):
self._data = sequence_of_numbers

@property
@cache
def stdev(self):
return statistics.stdev(self._data)
If a mutable mapping is not available or if space-efficient key sharing is
desired, an effect similar to :func:`cached_property` can also be achieved by
stacking :func:`property` on top of :func:`lru_cache`. See
:ref:`faq-cache-method-calls` for more details on how this differs from :func:`cached_property`.

.. versionadded:: 3.8

Expand Down

0 comments on commit 0271e1c

Please sign in to comment.