MCPcopy
hub / github.com/danielgtaylor/python-betterproto / __getattribute__

Method __getattribute__

src/betterproto/__init__.py:821–852  ·  view source on GitHub ↗

Lazily initialize default values to avoid infinite recursion for recursive message types. Raise :class:`AttributeError` on attempts to access unset ``oneof`` fields.

(self, name: str)

Source from the content-addressed store, hash-verified

819 if not TYPE_CHECKING:
820
821 def __getattribute__(self, name: str) -> Any:
822 """
823 Lazily initialize default values to avoid infinite recursion for recursive
824 message types.
825 Raise :class:`AttributeError` on attempts to access unset ``oneof`` fields.
826 """
827 try:
828 group_current = super().__getattribute__("_group_current")
829 except AttributeError:
830 pass
831 else:
832 if name not in {"__class__", "_betterproto"}:
833 group = self._betterproto.oneof_group_by_field.get(name)
834 if group is not None and group_current[group] != name:
835 if sys.version_info < (3, 10):
836 raise AttributeError(
837 f"{group!r} is set to {group_current[group]!r}, not {name!r}"
838 )
839 else:
840 raise AttributeError(
841 f"{group!r} is set to {group_current[group]!r}, not {name!r}",
842 name=name,
843 obj=self,
844 )
845
846 value = super().__getattribute__(name)
847 if value is not PLACEHOLDER:
848 return value
849
850 value = self._get_field_default(name)
851 super().__setattr__(name, value)
852 return value
853
854 def __setattr__(self, attr: str, value: Any) -> None:
855 if (

Calls 3

_get_field_defaultMethod · 0.95
getMethod · 0.80
__setattr__Method · 0.45