MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / __getattr__

Method __getattr__

lib/sqlalchemy/orm/util.py:775–802  ·  view source on GitHub ↗
(self, key: str)

Source from the content-addressed store, hash-verified

773 return obj
774
775 def __getattr__(self, key: str) -> Any:
776 try:
777 _aliased_insp = self.__dict__["_aliased_insp"]
778 except KeyError:
779 raise AttributeError()
780 else:
781 target = _aliased_insp._target
782 # maintain all getattr mechanics
783 attr = getattr(target, key)
784
785 # attribute is a method, that will be invoked against a
786 # "self"; so just return a new method with the same function and
787 # new self
788 if hasattr(attr, "__call__") and hasattr(attr, "__self__"):
789 return types.MethodType(attr.__func__, self)
790
791 # attribute is a descriptor, that will be invoked against a
792 # "self"; so invoke the descriptor against this self
793 if hasattr(attr, "__get__"):
794 attr = attr.__get__(None, self)
795
796 # attributes within the QueryableAttribute system will want this
797 # to be invoked so the object can be adapted
798 if hasattr(attr, "adapt_to_entity"):
799 attr = attr.adapt_to_entity(_aliased_insp)
800 setattr(self, key, attr)
801
802 return attr
803
804 def _get_from_serialized(
805 self, key: str, mapped_class: _O, aliased_insp: AliasedInsp[_O]

Callers

nothing calls this directly

Calls 2

__get__Method · 0.45
adapt_to_entityMethod · 0.45

Tested by

no test coverage detected