MCPcopy Index your code
hub / github.com/sqlalchemy/sqlalchemy / TypeCoerce

Class TypeCoerce

lib/sqlalchemy/sql/elements.py:3756–3817  ·  view source on GitHub ↗

Represent a Python-side type-coercion wrapper. :class:`.TypeCoerce` supplies the :func:`_expression.type_coerce` function; see that function for usage details. .. seealso:: :func:`_expression.type_coerce` :func:`.cast`

Source from the content-addressed store, hash-verified

3754
3755
3756class TypeCoerce(WrapsColumnExpression[_T]):
3757 """Represent a Python-side type-coercion wrapper.
3758
3759 :class:`.TypeCoerce` supplies the :func:`_expression.type_coerce`
3760 function; see that function for usage details.
3761
3762 .. seealso::
3763
3764 :func:`_expression.type_coerce`
3765
3766 :func:`.cast`
3767
3768 """
3769
3770 __visit_name__ = "type_coerce"
3771
3772 _traverse_internals: _TraverseInternalsType = [
3773 ("clause", InternalTraversal.dp_clauseelement),
3774 ("type", InternalTraversal.dp_type),
3775 ]
3776
3777 clause: ColumnElement[Any]
3778 type: TypeEngine[_T]
3779
3780 def __init__(
3781 self,
3782 expression: _ColumnExpressionArgument[Any],
3783 type_: _TypeEngineArgument[_T],
3784 ):
3785 self.type = type_api.to_instance(type_)
3786 self.clause = coercions.expect(
3787 roles.ExpressionElementRole,
3788 expression,
3789 type_=self.type,
3790 apply_propagate_attrs=self,
3791 )
3792
3793 @util.ro_non_memoized_property
3794 def _from_objects(self) -> List[FromClause]:
3795 return self.clause._from_objects
3796
3797 @HasMemoized.memoized_attribute
3798 def typed_expression(self):
3799 if isinstance(self.clause, BindParameter):
3800 bp = self.clause._clone()
3801 bp.type = self.type
3802 return bp
3803 else:
3804 return self.clause
3805
3806 @property
3807 def wrapped_column_expression(self):
3808 return self.clause
3809
3810 def self_group(
3811 self, against: Optional[OperatorType] = None
3812 ) -> TypeCoerce[_T]:
3813 grouped = self.clause.self_group(against=against)

Callers 2

self_groupMethod · 0.85
type_coerceFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected