MCPcopy Index your code
hub / github.com/python-openxml/python-docx / __get__

Method __get__

src/docx/shared.py:215–242  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.

Callers

nothing calls this directly

Calls 1

getMethod · 0.45

Tested by

no test coverage detected