Skip to content

Commit 4829c5b

Browse files
committed
Avoid the MRO loop in _make_cached_property_uncached if we can
1 parent 67fb291 commit 4829c5b

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

src/attr/_make.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -542,12 +542,15 @@ def _make_cached_property_uncached(original_cached_property_func, cls):
542542
"@property",
543543
defline,
544544
*doc_lines,
545-
" for entry in type.__dict__['__mro__'].__get__(self.__class__):",
546-
f" if '{name}_cache' in entry.__dict__:",
547-
f" descriptor = entry.__dict__['{name}_cache']",
548-
" break",
549-
" else:",
550-
" raise AttributeError('No descriptor')",
545+
" clsd = self.__class__.__dict__",
546+
f" descriptor = clsd.get('{name}_cache')",
547+
" if descriptor is None:",
548+
" for entry in type.__dict__['__mro__'].__get__(self.__class__)[1:]:",
549+
f" descriptor = entry.__dict__.get('{name}_cache')",
550+
" if descriptor is not None:",
551+
" break",
552+
" else:",
553+
" raise AttributeError('No descriptor')",
551554
" try:",
552555
" return descriptor.__get__(self, self.__class__)",
553556
" except AttributeError:",

0 commit comments

Comments
 (0)