Skip to content

Commit 0609b6e

Browse files
committed
Go back to the try-catch, but call __get__ directly
1 parent f2d45b0 commit 0609b6e

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/attr/_make.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,9 +506,10 @@ def _make_cached_property_getattr(cached_properties, original_getattr, cls):
506506
" func = cached_properties.get(item)",
507507
" if func is not None:",
508508
" cache = item + '_cache'",
509-
" if cache in self.__slots__:",
510-
" return self.__getattribute__(cache)",
511-
" else:",
509+
" cached = getattr_static(self, cache)",
510+
" try:",
511+
" return cached.__get__(self, type(self))",
512+
" except AttributeError:",
512513
" result = func(self)",
513514
" _setter = _cached_setattr_get(self)",
514515
" _setter(cache, result)",
@@ -545,6 +546,7 @@ def _make_cached_property_getattr(cached_properties, original_getattr, cls):
545546
"cached_properties": cached_properties,
546547
"_cached_setattr_get": _OBJ_SETATTR.__get__,
547548
"original_getattr": original_getattr,
549+
"getattr_static": inspect.getattr_static,
548550
}
549551

550552
return _linecache_and_compile(

0 commit comments

Comments
 (0)