code: def cast_to_type(obj, out_type):
      
      in_type = type(obj)
      if out_type is in_type:
          # no need to cast.
          return obj
      else:
          return out_type(obj)
docs: Cast obj to out_type if it's not out_type already.
  
      If the obj happens to be out_type already, it just returns obj as is.
  
      Args:
          obj: input object
          out_type: type.
  
      Returns:
          obj cast to out_type. Usual python conversion / casting rules apply.