Refs #30278 -- Doc'd behavior of del on an unaccessed cached_property.

Thanks to Curtis Maloney for the description of the problem.
This commit is contained in:
Matthew Schinckel 2019-03-30 23:59:03 +10:30 committed by Tim Graham
parent ad72895c60
commit c3c2ec54f5
1 changed files with 4 additions and 0 deletions

View File

@ -473,6 +473,10 @@ https://web.archive.org/web/20110718035220/http://diveintomark.org/archives/2004
# set a value manually, that will persist on the instance until cleared # set a value manually, that will persist on the instance until cleared
person.friends = ["Huckleberry Finn", "Tom Sawyer"] person.friends = ["Huckleberry Finn", "Tom Sawyer"]
Because of the way the `descriptor protocol
<descriptor-invocation>`_ works, using ``del`` (or ``delattr``) on a
``cached_property`` that hasn't been accessed raises ``AttributeError``.
As well as offering potential performance advantages, ``@cached_property`` As well as offering potential performance advantages, ``@cached_property``
can ensure that an attribute's value does not change unexpectedly over the can ensure that an attribute's value does not change unexpectedly over the
life of an instance. This could occur with a method whose computation is life of an instance. This could occur with a method whose computation is