Skip to content

Commit

Permalink
remove unnecessary check for existing value
Browse files Browse the repository at this point in the history
  • Loading branch information
carljm committed Feb 13, 2023
1 parent 477e6b3 commit 31f0d54
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions Lib/functools.py
Original file line number Diff line number Diff line change
Expand Up @@ -959,8 +959,6 @@ def __isabstractmethod__(self):
### cached_property() - computed once per instance, cached as attribute
################################################################################

_NOT_FOUND = object()


class cached_property:
def __init__(self, func):
Expand Down Expand Up @@ -991,17 +989,15 @@ def __get__(self, instance, owner=None):
f"instance to cache {self.attrname!r} property."
)
raise TypeError(msg) from None
val = cache.get(self.attrname, _NOT_FOUND)
if val is _NOT_FOUND:
val = self.func(instance)
try:
cache[self.attrname] = val
except TypeError:
msg = (
f"The '__dict__' attribute on {type(instance).__name__!r} instance "
f"does not support item assignment for caching {self.attrname!r} property."
)
raise TypeError(msg) from None
val = self.func(instance)
try:
cache[self.attrname] = val
except TypeError:
msg = (
f"The '__dict__' attribute on {type(instance).__name__!r} instance "
f"does not support item assignment for caching {self.attrname!r} property."
)
raise TypeError(msg) from None
return val

__class_getitem__ = classmethod(GenericAlias)

0 comments on commit 31f0d54

Please sign in to comment.