Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-21145: Add cached_property decorator in functools #6982

merged 12 commits into from Aug 28, 2018

More review feedback.

  • Loading branch information...
carljm committed May 20, 2018
commit 26f3f43e321f2e319f839299d7559d914372926f
@@ -883,15 +883,15 @@ def __init__(self, func):
self.__doc__ = func.__doc__
self.lock = RLock()

def __get__(self, obj, objtype=None):
if obj is None:
def __get__(self, instance, owner):
if instance is None:
return self
attrname = self.func.__name__
cache = obj.__dict__
cache = instance.__dict__
except AttributeError: # objects with __slots__ have no __dict__

This comment has been minimized.

Copy link

ncoghlan Aug 4, 2018


Tweak the comment here along similar lines to the note in the docs

msg = (
f"No '__dict__' attribute on {type(obj).__name__!r} "
f"No '__dict__' attribute on {type(instance).__name__!r} "
f"instance to cache {attrname!r} property."
raise TypeError(msg) from None
@@ -901,5 +901,5 @@ def __get__(self, obj, objtype=None):
# check if another thread filled cache while we awaited lock
val = cache.get(attrname, _NOT_FOUND)
if val is _NOT_FOUND:
val = cache[attrname] = self.func(obj)
val = cache[attrname] = self.func(instance)
return val
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.