def type_coerce(expression, type_):
 type_ = type_api.to_instance(type_)
 if hasattr(expression, u'__clause_element__'):
  return type_coerce(expression.__clause_element__(), type_)
 elif isinstance(expression, BindParameter):
  bp = expression._clone()
  bp.type = type_
  return bp
 elif (not isinstance(expression, Visitable)):
  if (expression is None):
   return Null()
  else:
   return literal(expression, type_=type_)
 else:
  return Label(None, expression, type_=type_)

def type_coerce ( expression , type_ ) : type_ = type_api . to_instance ( type_ ) if hasattr ( expression , u'__clause_element__' ) : return type_coerce ( expression . __clause_element__ ( ) , type_ ) elif isinstance ( expression , BindParameter ) : bp = expression . _clone ( ) bp . type = type_ return bp elif ( not isinstance ( expression , Visitable ) ) : if ( expression is None ) : return Null ( ) else : return literal ( expression , type_ = type_ ) else : return Label ( None , expression , type_ = type_ )
associate a sql expression with a particular type .