diff options
| author | Thomas Grainger <tagrain@gmail.com> | 2018-06-07 14:03:45 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2018-11-19 13:40:49 -0500 |
| commit | 06076999026091cf007d8ea69146340a361259f8 (patch) | |
| tree | 15849dd10829da13a6c09abf6bed9fe8f54acd42 /docs | |
| parent | 80ba7a881f9810404ba8a660548f1757f8243562 (diff) | |
Fixed #29478 -- Added support for mangled names to cached_property.
Co-Authored-By: Sergey Fedoseev <fedoseev.sergey@gmail.com>
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/ref/utils.txt | 21 | ||||
| -rw-r--r-- | docs/releases/2.2.txt | 29 |
2 files changed, 44 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') diff --git a/docs/releases/2.2.txt b/docs/releases/2.2.txt index aa04b34f0e..02d3fd8682 100644 --- a/docs/releases/2.2.txt +++ b/docs/releases/2.2.txt @@ -351,6 +351,35 @@ To simplify a few parts of Django's database handling, `sqlparse <https://pypi.org/project/sqlparse/>`_ is now a required dependency. It's automatically installed along with Django. +``cached_property`` aliases +--------------------------- + +In usage like:: + + from django.utils.functional import cached_property + + class A: + + @cached_property + def base(self): + return ... + + alias = base + +``alias`` is not cached. Such usage now raises ``TypeError: Cannot assign the +same cached_property to two different names ('base' and 'alias').`` on Python +3.6 and later. + +Use this instead:: + + import operator + + class A: + + ... + + alias = property(operator.attrgetter('base')) + Miscellaneous ------------- |
