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)
| 164 | functools.update_wrapper(self, fget) # pyright: ignore |
| 165 | |
| 166 | def __get__(self, obj: Any, type: Any = None) -> _T: |
| 167 | """Called on each access of 'fget' attribute on class or instance. |
| 168 | |
| 169 | *self* is this instance of a lazyproperty descriptor "wrapping" the property |
| 170 | method it decorates (`fget`, nominally). |
| 171 | |
| 172 | *obj* is the "host" object instance when the attribute is accessed from an |
| 173 | object instance, e.g. `obj = Obj(); obj.fget`. *obj* is None when accessed on |
| 174 | the class, e.g. `Obj.fget`. |
| 175 | |
| 176 | *type* is the class hosting the decorated getter method (`fget`) on both class |
| 177 | and instance attribute access. |
| 178 | """ |
| 179 | # --- when accessed on class, e.g. Obj.fget, just return this descriptor |
| 180 | # --- instance (patched above to look like fget). |
| 181 | if obj is None: |
| 182 | return self # type: ignore |
| 183 | |
| 184 | # --- when accessed on instance, start by checking instance __dict__ for |
| 185 | # --- item with key matching the wrapped function's name |
| 186 | value = obj.__dict__.get(self._name) |
| 187 | if value is None: |
| 188 | # --- on first access, the __dict__ item will be absent. Evaluate fget() |
| 189 | # --- and store that value in the (otherwise unused) host-object |
| 190 | # --- __dict__ value of same name ('fget' nominally) |
| 191 | value = self._fget(obj) |
| 192 | obj.__dict__[self._name] = value |
| 193 | return cast(_T, value) |
| 194 | |
| 195 | def __set__(self, obj: Any, value: Any) -> None: |
| 196 | """Raises unconditionally, to preserve read-only behavior. |