From 13b002c63cdef03f825fe3fc7ba9d89e34ebf140 Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Sat, 18 Jan 2020 13:51:11 -0600 Subject: simplify SettableProperty to be a non-data-descriptor to avoid caching itself --- src/pyramid/decorator.py | 4 ++++ src/pyramid/util.py | 13 +++---------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/pyramid/decorator.py b/src/pyramid/decorator.py index 89cbb0f6e..525111ccd 100644 --- a/src/pyramid/decorator.py +++ b/src/pyramid/decorator.py @@ -41,5 +41,9 @@ class reify(object): if inst is None: return self val = self.wrapped(inst) + # reify is a non-data-descriptor which is leveraging the fact + # that it is not invoked if the equivalent attribute is defined in the + # object's dict, so the setattr here effectively hides this descriptor + # from subsequent lookups setattr(inst, self.wrapped.__name__, val) return val diff --git a/src/pyramid/util.py b/src/pyramid/util.py index fb8608512..bc589b36f 100644 --- a/src/pyramid/util.py +++ b/src/pyramid/util.py @@ -74,6 +74,8 @@ def as_sorted_tuple(val): class SettableProperty(object): + # this is just like reify but does not store the computed result on + # the class such that subsequent invocations invoke the callable again def __init__(self, wrapped): self.wrapped = wrapped functools.update_wrapper(self, wrapped) @@ -81,16 +83,7 @@ class SettableProperty(object): def __get__(self, obj, type=None): if obj is None: # pragma: no cover return self - value = obj.__dict__.get(self.wrapped.__name__, _marker) - if value is _marker: - value = self.wrapped(obj) - return value - - def __set__(self, obj, value): - obj.__dict__[self.wrapped.__name__] = value - - def __delete__(self, obj): - del obj.__dict__[self.wrapped.__name__] + return self.wrapped(obj) class InstancePropertyHelper(object): -- cgit v1.2.3