summaryrefslogtreecommitdiff
path: root/docs/ref
diff options
context:
space:
mode:
authorThomas Grainger <tagrain@gmail.com>2018-06-07 14:03:45 +0100
committerTim Graham <timograham@gmail.com>2018-11-19 13:40:49 -0500
commit06076999026091cf007d8ea69146340a361259f8 (patch)
tree15849dd10829da13a6c09abf6bed9fe8f54acd42 /docs/ref
parent80ba7a881f9810404ba8a660548f1757f8243562 (diff)
Fixed #29478 -- Added support for mangled names to cached_property.
Co-Authored-By: Sergey Fedoseev <fedoseev.sergey@gmail.com>
Diffstat (limited to 'docs/ref')
-rw-r--r--docs/ref/utils.txt21
1 files changed, 15 insertions, 6 deletions
diff --git a/docs/ref/utils.txt b/docs/ref/utils.txt
index 6f529d14fb..06de2731ec 100644
--- a/docs/ref/utils.txt
+++ b/docs/ref/utils.txt
@@ -492,13 +492,19 @@ https://web.archive.org/web/20110718035220/http://diveintomark.org/archives/2004
database by some other process in the brief interval between subsequent
invocations of a method on the same instance.
- You can use the ``name`` argument to make cached properties of other
- methods. For example, if you had an expensive ``get_friends()`` method and
- wanted to allow calling it without retrieving the cached value, you could
- write::
+ You can make cached properties of methods. For example, if you had an
+ expensive ``get_friends()`` method and wanted to allow calling it without
+ retrieving the cached value, you could write::
friends = cached_property(get_friends, name='friends')
+ You only need the ``name`` argument for Python < 3.6 support.
+
+ .. versionchanged:: 2.2
+
+ Older versions of Django require the ``name`` argument for all versions
+ of Python.
+
While ``person.get_friends()`` will recompute the friends on each call, the
value of the cached property will persist until you delete it as described
above::
@@ -510,8 +516,11 @@ https://web.archive.org/web/20110718035220/http://diveintomark.org/archives/2004
.. warning::
- ``cached_property`` doesn't work properly with a mangled__ name unless
- it's passed a ``name`` of the form ``_Class__attribute``::
+ .. _cached-property-mangled-name:
+
+ On Python < 3.6, ``cached_property`` doesn't work properly with a
+ mangled__ name unless it's passed a ``name`` of the form
+ ``_Class__attribute``::
__friends = cached_property(get_friends, name='_Person__friends')