Cast a value to the type of the column.

        Primarily used to check that a value is valid; it will throw an
        exception otherwise
196273
def python_cast(self, v):
        

        if self.type_is_time():
            dt = dateutil.parser.parse(v)

            if self.datatype == Column.DATATYPE_TIME:
                dt = dt.time()
            if not isinstance(dt, self.python_type):
                raise TypeError('{} was parsed to {}, expected {}'.format(v, type(dt), self.python_type))

            return dt
        else:
            # This isn't calling the python_type method -- it's getting a python type, then instantialting it,
            # such as "int(v)"
            return self.python_type(v)
451242
function tryConvertType(typeToConvert, value) {
  if (typeToConvert === 'string') {
    return value && value.toString();
  } else if (typeToConvert === 'number') {
    return Number(value);
  } else {
    return value;
  }
}
778529
@SuppressWarnings("PMD.LooseCoupling")
    public static Object castValue(Method m, Class<?> castType, String value) {

        try {
            if (castType.isEnum()) {
                Method valueOf;
                try {
                    valueOf = castType.getMethod("valueOf", String.class);
                    return valueOf.invoke(null, value);
                } catch (Exception e) {
                    log.info("enum value of excute error : (" + castType.getName() + ") | " + value);
                    return null;
                }
            } else if (castType == Integer.class || castType == int.class) {
                return Integer.parseInt(value);
            } else if (castType == Long.class || castType == long.class) {
                return Long.parseLong(value);
            } else if (castType == Double.class || castType == double.class) {
                return Double.parseDouble(value);
            } else if (castType == Boolean.class || castType == boolean.class) {
                return Boolean.parseBoolean(value);
            } else if (castType == Float.class || castType == float.class) {
                return Float.parseFloat(value);
            } else if (castType == String.class) {
                return value;
            } else if (castType == ArrayList.class || castType == List.class) {
                ParameterizedType paramType = (ParameterizedType) m.getGenericParameterTypes()[0];
                Class<?> paramClass = (Class<?>) paramType.getActualTypeArguments()[0];
                List<Object> castList = new ArrayList<>();
                String[] values = value.split(",");
                for (String v : values) {
                    castList.add(castValue(m, paramClass, v));
                }

                return castList;
            } else {
                log.info("invalid castType : " + castType);
                return null;
            }
        } catch (NumberFormatException e) {
            log.info("value : " + value + " is invalid value, setter parameter type is  : " + castType);
            return null;
        }
    }
966630
def cast_value(parent, value)
      if !allow_blank && value.to_s.empty?
        nil
      else
        value = typecast_value(parent, self, value)
        associate_casted_value_to_parent(parent, value)
      end
    end
164139
public static Object convertExample(String value, String type) {
        if (value == null) {
            return null;
        }

        try {
            switch (type) {
                case "integer":
                    return Integer.valueOf(value);
                case "number":
                    return Float.valueOf(value);
                case "boolean":
                    return Boolean.valueOf(value);
                case "string":
                    return value;
                default:
                    return value;
            }
        } catch (NumberFormatException e) {
            throw new RuntimeException(String.format("Value '%s' cannot be converted to '%s'", value, type), e);
        }
    }
1227398
def type_cast_value(self, ctx, value):
        
        if self.type.is_composite:
            if self.nargs <= 1:
                raise TypeError('Attempted to invoke composite type '
                                'but nargs has been set to %s.  This is '
                                'not supported; nargs needs to be set to '
                                'a fixed value > 1.' % self.nargs)
            if self.multiple:
                return tuple(self.type(x or (), self, ctx) for x in value or ())
            return self.type(value or (), self, ctx)

        def _convert(value, level):
            if level == 0:
                return self.type(value, self, ctx)
            return tuple(_convert(x, level - 1) for x in value or ())
        return _convert(value, (self.nargs != 1) + bool(self.multiple))
852489
def cast_value(parent, value)
      raise "An array inside an array cannot be casted, use CastedModel" if value.is_a?(Array)
      value = typecast_value(value, self)
      associate_casted_value_to_parent(parent, value)
    end
743521
protected function castToDb($value, $column)
    {
        if ($this->hasCast($column) && !$this->isIgnoreCast($value)) {
            $value = $this->toDbType($value, $this->casts[$column]);
        }

        return $value;
    }
957701
static boolean isBshAssignable( Class toType, Class fromType )
    {
        try {
            return castObject(
                toType, fromType, null/*fromValue*/,
                ASSIGNMENT, true/*checkOnly*/
            ) == VALID_CAST;
        } catch ( UtilEvalError e ) {
            // This should not happen with checkOnly true
            throw new InterpreterError("err in cast check: "+e, e);
        }
    }
810535
private Object correctDataType(Object value, String dataType) {
		if(value == null ){return null;}
		return value;
	}
593045
def _cast_to_type(self, value):
        
        try:
            return float(value)
        except (ValueError, TypeError):
            self.fail('invalid', value=value)
1360598
function cast(values, name) {
  var value = values && typeof values === 'string' ? [values] : values

  if (!value || typeof value !== 'object' || !('length' in value)) {
    throw new Error(
      'Invalid ' + name + ' `' + value + '`, expected non-empty string'
    )
  }

  return value
}
1184024
def _is_valid(self, value):
        

        # Entities have an istypeof method that can perform more sophisticated
        # type checking.
        if hasattr(self._type, "istypeof"):
            return self._type.istypeof(value)
        else:
            return isinstance(value, self._type)
880459
function __typeCheck(type, valueToCheck, optional) {
    var correct = typeof(valueToCheck) == type;
    if(optional) {
        // Exception if the variable is optional, than it also may be undefined or null
        correct = correct || valueToCheck === undefined || valueToCheck === null;
    }
    if(!correct) {
        throw new Error("Invalid argument type received; expected "+type+
            ", but received "+typeof(valueToCheck));
    }
}
1070325
def is_valid_value(value, type):
    # type: (Any, Any) -> List
    """"""
    if isinstance(type, GraphQLNonNull):
        of_type = type.of_type
        if value is None:
            return [u'Expected "{}", found null.'.format(type)]

        return is_valid_value(value, of_type)

    if value is None:
        return _empty_list

    if isinstance(type, GraphQLList):
        item_type = type.of_type
        if not isinstance(value, string_types) and isinstance(value, Iterable):
            errors = []
            for i, item in enumerate(value):
                item_errors = is_valid_value(item, item_type)
                for error in item_errors:
                    errors.append(u"In element #{}: {}".format(i, error))

            return errors

        else:
            return is_valid_value(value, item_type)

    if isinstance(type, GraphQLInputObjectType):
        if not isinstance(value, Mapping):
            return [u'Expected "{}", found not an object.'.format(type)]

        fields = type.fields
        errors = []

        for provided_field in sorted(value.keys()):
            if provided_field not in fields:
                errors.append(u'In field "{}": Unknown field.'.format(provided_field))

        for field_name, field in fields.items():
            subfield_errors = is_valid_value(value.get(field_name), field.type)
            errors.extend(
                u'In field "{}": {}'.format(field_name, e) for e in subfield_errors
            )

        return errors

    assert isinstance(type, (GraphQLScalarType, GraphQLEnumType)), "Must be input type"

    # Scalar/Enum input checks to ensure the type can parse the value to
    # a non-null value.
    parse_result = type.parse_value(value)
    if parse_result is None:
        return [u'Expected type "{}", found {}.'.format(type, json.dumps(value))]

    return _empty_list
544567
protected function castToPhp($value, $column)
    {
        if ($value !== null && $this->hasCast($column) && !$this->isIgnoreCast($value)) {
            $value = $this->toPhpType($value, $this->casts[$column]);
        }

        return $value;
    }
913946
public static <T> T cast(Object value, Class<T> type) {
        if (null == value) {
            return null;
        }
        if (!type.isAssignableFrom(value.getClass())) {
            if (is(type, int.class, Integer.class)) {
                value = Integer.parseInt(value.toString());
            } else if (is(type, long.class, Long.class)) {
                value = Long.parseLong(value.toString());
            } else if (is(type, float.class, Float.class)) {
                value = Float.parseFloat(value.toString());
            } else if (is(type, double.class, Double.class)) {
                value = Double.parseDouble(value.toString());
            } else if (is(type, boolean.class, Boolean.class)) {
                value = Boolean.parseBoolean(value.toString());
            } else if (is(type, String.class)) {
                value = value.toString();
            }
        }
        return (T) value;
    }