MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / InstrumentedAttribute

Class InstrumentedAttribute

lib/sqlalchemy/orm/attributes.py:509–569  ·  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

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

Callers 1

register_descriptorFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected