Called on each access of 'fget' attribute on class or instance. *self* is this instance of a lazyproperty descriptor "wrapping" the property method it decorates (`fget`, nominally). *obj* is the "host" object instance when the attribute is accessed from an object in
(self, obj: Any, type: Any = None)
| 213 | functools.update_wrapper(self, fget) # pyright: ignore |
| 214 | |
| 215 | def __get__(self, obj: Any, type: Any = None) -> T: |
| 216 | """Called on each access of 'fget' attribute on class or instance. |
| 217 | |
| 218 | *self* is this instance of a lazyproperty descriptor "wrapping" the property |
| 219 | method it decorates (`fget`, nominally). |
| 220 | |
| 221 | *obj* is the "host" object instance when the attribute is accessed from an |
| 222 | object instance, e.g. `obj = Obj(); obj.fget`. *obj* is None when accessed on |
| 223 | the class, e.g. `Obj.fget`. |
| 224 | |
| 225 | *type* is the class hosting the decorated getter method (`fget`) on both class |
| 226 | and instance attribute access. |
| 227 | """ |
| 228 | # --- when accessed on class, e.g. Obj.fget, just return this descriptor |
| 229 | # --- instance (patched above to look like fget). |
| 230 | if obj is None: |
| 231 | return self # type: ignore |
| 232 | |
| 233 | # --- when accessed on instance, start by checking instance __dict__ for |
| 234 | # --- item with key matching the wrapped function's name |
| 235 | value = obj.__dict__.get(self._name) |
| 236 | if value is None: |
| 237 | # --- on first access, the __dict__ item will be absent. Evaluate fget() |
| 238 | # --- and store that value in the (otherwise unused) host-object |
| 239 | # --- __dict__ value of same name ('fget' nominally) |
| 240 | value = self._fget(obj) |
| 241 | obj.__dict__[self._name] = value |
| 242 | return cast(T, value) |
| 243 | |
| 244 | def __set__(self, obj: Any, value: Any) -> None: |
| 245 | """Raises unconditionally, to preserve read-only behavior. |