mirror of
https://github.com/python/cpython.git
synced 2025-11-10 22:36:18 +00:00
Doc: Add missing entry for functools.cached_property (GH-16803)
This commit is contained in:
parent
f33c57d5c7
commit
93b81e1fcb
1 changed files with 16 additions and 0 deletions
|
|
@ -683,6 +683,22 @@ than as a function returning a decorator. So both of these are now supported::
|
||||||
|
|
||||||
(Contributed by Raymond Hettinger in :issue:`36772`.)
|
(Contributed by Raymond Hettinger in :issue:`36772`.)
|
||||||
|
|
||||||
|
Added a new :func:`functools.cached_property` decorator, for computed properties
|
||||||
|
cached for the life of the instance. ::
|
||||||
|
|
||||||
|
import functools
|
||||||
|
import statistics
|
||||||
|
|
||||||
|
class Dataset:
|
||||||
|
def __init__(self, sequence_of_numbers):
|
||||||
|
self.data = sequence_of_numbers
|
||||||
|
|
||||||
|
@functools.cached_property
|
||||||
|
def variance(self):
|
||||||
|
return statistics.variance(self.data)
|
||||||
|
|
||||||
|
(Contributed by Carl Meyer in :issue:`21145`)
|
||||||
|
|
||||||
|
|
||||||
gc
|
gc
|
||||||
--
|
--
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue