class documentation

A decorator which allows definition of a Python descriptor with both instance-level and class-level behavior.

Method __delete__ Undocumented
Method __get__ Undocumented
Method __init__ Create a new :class:`.hybrid_property`.
Method __set__ Undocumented
Method comparator Provide a modifying decorator that defines a custom comparator producing method.
Method deleter Provide a modifying decorator that defines a deletion method.
Method expression Provide a modifying decorator that defines a SQL-expression producing method.
Method getter Provide a modifying decorator that defines a getter method.
Method setter Provide a modifying decorator that defines a setter method.
Method update_expression Provide a modifying decorator that defines an UPDATE tuple producing method.
Class Variable __name__ Undocumented
Class Variable is_attribute True if this object is a Python :term:`descriptor`.
Instance Variable custom_comparator Undocumented
Instance Variable expr Undocumented
Instance Variable fdel Undocumented
Instance Variable fget Undocumented
Instance Variable fset Undocumented
Instance Variable update_expr Undocumented
Property inplace Return the inplace mutator for this :class:`.hybrid_property`.
Property overrides Prefix for a method that is overriding an existing attribute.
Class _InPlace A builder helper for .hybrid_property.
Method _copy Undocumented
Method _get_comparator Undocumented
Method _get_expr Undocumented
Property _expr_comparator Undocumented

Inherited from InspectionAttrInfo:

Class Variable __slots__ Undocumented
Property info Info dictionary associated with the object, allowing user-defined data to be associated with this :class:`.InspectionAttr`.

Inherited from InspectionAttr (via InspectionAttrInfo):

Class Variable is_aliased_class True if this object is an instance of :class:`.AliasedClass`.
Class Variable is_bundle True if this object is an instance of :class:`.Bundle`.
Class Variable is_clause_element True if this object is an instance of :class:`_expression.ClauseElement`.
Class Variable is_instance True if this object is an instance of :class:`.InstanceState`.
Class Variable is_mapper True if this object is an instance of :class:`_orm.Mapper`.
Class Variable is_property True if this object is an instance of :class:`.MapperProperty`.
Class Variable is_selectable Return True if this object is an instance of :class:`_expression.Selectable`.
Class Variable _is_internal_proxy True if this object is an internal proxy object.
def __delete__(self, instance: object): (source)

Undocumented

@overload
def __get__(self, instance: Any, owner: Literal[None]) -> Self:
@overload
def __get__(self, instance: Literal[None], owner: Type[object]) -> _HybridClassLevelAccessor[_T]:
@overload
def __get__(self, instance: object, owner: Type[object]) -> _T:
(source)

Undocumented

Create a new :class:`.hybrid_property`. Usage is typically via decorator:: from sqlalchemy.ext.hybrid import hybrid_property class SomeClass: @hybrid_property def value(self): return self._value @value.setter def value(self, value): self._value = value

def __set__(self, instance: object, value: Any): (source)

Undocumented

def comparator(self, comparator: _HybridComparatorCallableType[_T]) -> hybrid_property[_T]: (source)

Provide a modifying decorator that defines a custom comparator producing method. The return value of the decorated method should be an instance of :class:`~.hybrid.Comparator`. .. note:: The :meth:`.hybrid_property.comparator` decorator **replaces** the use of the :meth:`.hybrid_property.expression` decorator. They cannot be used together. When a hybrid is invoked at the class level, the :class:`~.hybrid.Comparator` object given here is wrapped inside of a specialized :class:`.QueryableAttribute`, which is the same kind of object used by the ORM to represent other mapped attributes. The reason for this is so that other class-level attributes such as docstrings and a reference to the hybrid itself may be maintained within the structure that's returned, without any modifications to the original comparator object passed in. .. note:: When referring to a hybrid property from an owning class (e.g. ``SomeClass.some_hybrid``), an instance of :class:`.QueryableAttribute` is returned, representing the expression or comparator object as this hybrid object. However, that object itself has accessors called ``expression`` and ``comparator``; so when attempting to override these decorators on a subclass, it may be necessary to qualify it using the :attr:`.hybrid_property.overrides` modifier first. See that modifier for details.

def deleter(self, fdel: _HybridDeleterType[_T]) -> hybrid_property[_T]: (source)

Provide a modifying decorator that defines a deletion method.

Provide a modifying decorator that defines a SQL-expression producing method. When a hybrid is invoked at the class level, the SQL expression given here is wrapped inside of a specialized :class:`.QueryableAttribute`, which is the same kind of object used by the ORM to represent other mapped attributes. The reason for this is so that other class-level attributes such as docstrings and a reference to the hybrid itself may be maintained within the structure that's returned, without any modifications to the original SQL expression passed in. .. note:: When referring to a hybrid property from an owning class (e.g. ``SomeClass.some_hybrid``), an instance of :class:`.QueryableAttribute` is returned, representing the expression or comparator object as well as this hybrid object. However, that object itself has accessors called ``expression`` and ``comparator``; so when attempting to override these decorators on a subclass, it may be necessary to qualify it using the :attr:`.hybrid_property.overrides` modifier first. See that modifier for details. .. seealso:: :ref:`hybrid_distinct_expression`

Provide a modifying decorator that defines a getter method. .. versionadded:: 1.2

Provide a modifying decorator that defines a setter method.

def update_expression(self, meth: _HybridUpdaterType[_T]) -> hybrid_property[_T]: (source)

Provide a modifying decorator that defines an UPDATE tuple producing method. The method accepts a single value, which is the value to be rendered into the SET clause of an UPDATE statement. The method should then process this value into individual column expressions that fit into the ultimate SET clause, and return them as a sequence of 2-tuples. Each tuple contains a column expression as the key and a value to be rendered. E.g.:: class Person(Base): # ... first_name = Column(String) last_name = Column(String) @hybrid_property def fullname(self): return first_name + " " + last_name @fullname.update_expression def fullname(cls, value): fname, lname = value.split(" ", 1) return [ (cls.first_name, fname), (cls.last_name, lname) ] .. versionadded:: 1.2

__name__: str = (source)

Undocumented

is_attribute: bool = (source)

True if this object is a Python :term:`descriptor`. This can refer to one of many types. Usually a :class:`.QueryableAttribute` which handles attributes events on behalf of a :class:`.MapperProperty`. But can also be an extension type such as :class:`.AssociationProxy` or :class:`.hybrid_property`. The :attr:`.InspectionAttr.extension_type` will refer to a constant identifying the specific subtype. .. seealso:: :attr:`_orm.Mapper.all_orm_descriptors`

custom_comparator = (source)

Undocumented

update_expr = (source)

Undocumented

Return the inplace mutator for this :class:`.hybrid_property`. This is to allow in-place mutation of the hybrid, allowing the first hybrid method of a certain name to be re-used in order to add more methods without having to name those methods the same, e.g.:: class Interval(Base): # ... @hybrid_property def radius(self) -> float: return abs(self.length) / 2 @radius.inplace.setter def _radius_setter(self, value: float) -> None: self.length = value * 2 @radius.inplace.expression def _radius_expression(cls) -> ColumnElement[float]: return type_coerce(func.abs(cls.length) / 2, Float) .. versionadded:: 2.0.4 .. seealso:: :ref:`hybrid_pep484_naming`

@property
overrides: Self = (source)

Prefix for a method that is overriding an existing attribute. The :attr:`.hybrid_property.overrides` accessor just returns this hybrid object, which when called at the class level from a parent class, will de-reference the "instrumented attribute" normally returned at this level, and allow modifying decorators like :meth:`.hybrid_property.expression` and :meth:`.hybrid_property.comparator` to be used without conflicting with the same-named attributes normally present on the :class:`.QueryableAttribute`:: class SuperClass: # ... @hybrid_property def foobar(self): return self._foobar class SubClass(SuperClass): # ... @SuperClass.foobar.overrides.expression def foobar(cls): return func.subfoobar(self._foobar) .. versionadded:: 1.2 .. seealso:: :ref:`hybrid_reuse_subclass`

def _copy(self, **kw: Any) -> hybrid_property[_T]: (source)

Undocumented

def _get_comparator(self, comparator: Any) -> Callable[[Any], _HybridClassLevelAccessor[_T]]: (source)

Undocumented

Undocumented

@util.memoized_property
_expr_comparator: Callable[[Any], _HybridClassLevelAccessor[_T]] = (source)

Undocumented