@@ -73,16 +73,31 @@ The :mod:`functools` module defines the following functions:
7373 def variance(self):
7474 return statistics.variance(self._data)
7575
76- .. versionadded :: 3.8
76+ Note, this decorator interferes with the operation of :pep: `412 `
77+ key-sharing dictionaries. This means that instance dictionaries
78+ can take more space than usual.
7779
78- .. note ::
80+ Also, this decorator requires that the ``__dict__ `` attribute on each instance
81+ be a mutable mapping. This means it will not work with some types, such as
82+ metaclasses (since the ``__dict__ `` attributes on type instances are
83+ read-only proxies for the class namespace), and those that specify
84+ ``__slots__ `` without including ``__dict__ `` as one of the defined slots
85+ (as such classes don't provide a ``__dict__ `` attribute at all).
86+
87+ If a mutable mapping is not available or if space-efficient key sharing
88+ is desired, an effect similar to :func: `cached_property ` can be achieved
89+ by a stacking :func: `property ` on top of :func: `cache `::
7990
80- This decorator requires that the ``__dict__ `` attribute on each instance
81- be a mutable mapping. This means it will not work with some types, such as
82- metaclasses (since the ``__dict__ `` attributes on type instances are
83- read-only proxies for the class namespace), and those that specify
84- ``__slots__ `` without including ``__dict__ `` as one of the defined slots
85- (as such classes don't provide a ``__dict__ `` attribute at all).
91+ class DataSet:
92+ def __init__(self, sequence_of_numbers):
93+ self._data = sequence_of_numbers
94+
95+ @property
96+ @cache
97+ def stdev(self):
98+ return statistics.stdev(self._data)
99+
100+ .. versionadded :: 3.8
86101
87102
88103.. function :: cmp_to_key(func)
@@ -658,4 +673,4 @@ callable, weak referencable, and can have attributes. There are some important
658673differences. For instance, the :attr: `~definition.__name__ ` and :attr: `__doc__ ` attributes
659674are not created automatically. Also, :class: `partial ` objects defined in
660675classes behave like static methods and do not transform into bound methods
661- during instance attribute look-up.
676+ during instance attribute look-up.
0 commit comments