summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Merickel <michael@merickel.org>2020-01-18 13:51:11 -0600
committerMichael Merickel <michael@merickel.org>2020-01-18 13:51:11 -0600
commit13b002c63cdef03f825fe3fc7ba9d89e34ebf140 (patch)
tree7c8d3f5d219b2c5a18d9fe7575f22d4c41a1d81a
parent9b83a51946c7125163ef80c8431630aef4656bbc (diff)
downloadpyramid-13b002c63cdef03f825fe3fc7ba9d89e34ebf140.tar.gz
pyramid-13b002c63cdef03f825fe3fc7ba9d89e34ebf140.tar.bz2
pyramid-13b002c63cdef03f825fe3fc7ba9d89e34ebf140.zip
simplify SettableProperty to be a non-data-descriptor to avoid caching itself
-rw-r--r--src/pyramid/decorator.py4
-rw-r--r--src/pyramid/util.py13
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):