diff options
| author | Collin Anderson <cmawebsite@gmail.com> | 2022-03-03 00:19:11 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-03-03 06:19:11 +0100 |
| commit | 5659015d3c1828e96c9318903f72a82e047f07fa (patch) | |
| tree | 898e616949410bc10627d7644bfbbe6df4927488 | |
| parent | 95b7d01d3856da323a610338aaa6882e82e4cc48 (diff) | |
Optimized lazy wrappers a bit.
This avoids an extra __getattribute__() call for self._wrapped.
| -rw-r--r-- | django/conf/__init__.py | 5 | ||||
| -rw-r--r-- | django/utils/functional.py | 5 |
2 files changed, 6 insertions, 4 deletions
diff --git a/django/conf/__init__.py b/django/conf/__init__.py index 55bf15a355..cb70a71791 100644 --- a/django/conf/__init__.py +++ b/django/conf/__init__.py @@ -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. diff --git a/django/utils/functional.py b/django/utils/functional.py index 5827389231..fd2c3c44d6 100644 --- a/django/utils/functional.py +++ b/django/utils/functional.py @@ -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 |
