diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2025-01-09 13:34:38 +0100 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2025-03-06 13:47:55 -0800 |
commit | f70945d1184a68be46bd38f0a4672d2bc88e99f2 (patch) | |
tree | 4d1f5627860581641646cc48972b8736736bda94 | |
parent | 1be473417a7634cd41fcee6abc71821798ae4de0 (diff) | |
download | meson-f70945d1184a68be46bd38f0a4672d2bc88e99f2.zip meson-f70945d1184a68be46bd38f0a4672d2bc88e99f2.tar.gz meson-f70945d1184a68be46bd38f0a4672d2bc88e99f2.tar.bz2 |
mesonlib: allow using lazy_property with "__"-named properties
These are given a name that is different from __func.__name__, so
store the name when the descriptor is placed in the class.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r-- | mesonbuild/utils/universal.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/mesonbuild/utils/universal.py b/mesonbuild/utils/universal.py index dda35cc..45c0b7c 100644 --- a/mesonbuild/utils/universal.py +++ b/mesonbuild/utils/universal.py @@ -2379,10 +2379,17 @@ class lazy_property(T.Generic[_T]): Due to Python's MRO that means that the calculated value will be found before this property, speeding up subsequent lookups. """ - def __init__(self, func: T.Callable[[T.Any], _T]): + def __init__(self, func: T.Callable[[T.Any], _T]) -> None: + self.__name: T.Optional[str] = None self.__func = func + def __set_name__(self, owner: T.Any, name: str) -> None: + if self.__name is None: + self.__name = name + else: + assert name == self.__name + def __get__(self, instance: object, cls: T.Type) -> _T: value = self.__func(instance) - setattr(instance, self.__func.__name__, value) + setattr(instance, self.__name, value) return value |