MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / InstrumentedAttribute

Class InstrumentedAttribute

lib/sqlalchemy/orm/attributes.py:515–575  ·  view source on GitHub ↗

Class bound instrumented attribute which adds basic :term:`descriptor` methods. See :class:`.QueryableAttribute` for a description of most features.

Source from the content-addressed store, hash-verified

513
514
515class InstrumentedAttribute(QueryableAttribute[_T_co]):
516 """Class bound instrumented attribute which adds basic
517 :term:`descriptor` methods.
518
519 See :class:`.QueryableAttribute` for a description of most features.
520
521
522 """
523
524 __slots__ = ()
525
526 inherit_cache = True
527 """:meta private:"""
528
529 # hack to make __doc__ writeable on instances of
530 # InstrumentedAttribute, while still keeping classlevel
531 # __doc__ correct
532
533 @util.rw_hybridproperty
534 def __doc__(self) -> Optional[str]:
535 return self._doc
536
537 @__doc__.setter # type: ignore
538 def __doc__(self, value: Optional[str]) -> None:
539 self._doc = value
540
541 @__doc__.classlevel # type: ignore
542 def __doc__(cls) -> Optional[str]:
543 return super().__doc__
544
545 def __set__(self, instance: object, value: Any) -> None:
546 self.impl.set(
547 instance_state(instance), instance_dict(instance), value, None
548 )
549
550 def __delete__(self, instance: object) -> None:
551 self.impl.delete(instance_state(instance), instance_dict(instance))
552
553 @overload
554 def __get__(
555 self, instance: None, owner: Any
556 ) -> InstrumentedAttribute[_T_co]: ...
557
558 @overload
559 def __get__(self, instance: object, owner: Any) -> _T_co: ...
560
561 def __get__(
562 self, instance: Optional[object], owner: Any
563 ) -> Union[InstrumentedAttribute[_T_co], _T_co]:
564 if instance is None:
565 return self
566
567 dict_ = instance_dict(instance)
568 if self.impl.supports_population and self.key in dict_:
569 return dict_[self.key] # type: ignore[no-any-return]
570 else:
571 try:
572 state = instance_state(instance)

Callers 1

_register_descriptorFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected