Optimized lazy wrappers a bit.

This avoids an extra __getattribute__() call for self._wrapped.
This commit is contained in:
Collin Anderson 2022-03-03 00:19:11 -05:00 committed by GitHub
parent 95b7d01d38
commit 5659015d3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View File

@ -88,9 +88,10 @@ class LazySettings(LazyObject):
def __getattr__(self, name):
"""Return the value of a setting and cache it in self.__dict__."""
if self._wrapped is empty:
if (_wrapped := self._wrapped) is empty:
self._setup(name)
val = getattr(self._wrapped, name)
_wrapped = self._wrapped
val = getattr(_wrapped, name)
# Special case some settings which require further modification.
# This is done here for performance reasons so the modified value is cached.

View File

@ -262,9 +262,10 @@ empty = object()
def new_method_proxy(func):
def inner(self, *args):
if self._wrapped is empty:
if (_wrapped := self._wrapped) is empty:
self._setup()
return func(self._wrapped, *args)
_wrapped = self._wrapped
return func(_wrapped, *args)
inner._mask_wrapped = False
return inner