def check_type(name, val, expected_type):
    """
    returns and converts if necessary
    :param name: the name of the value
    :param val: the value to check
    :param expected_type: the expected type
    """
    if isinstance(expected_type, list):
        if val not in expected_type:
            raise ValueError('{} is not a member of expected list {}, got {}'
                .format(name, expected_type, val))
    elif not isinstance(val, expected_type):
        raise ValueError("{} should be a '{}' but is of type '{}'.".format(
            name, expected_type.__name__, type(val).__name__))
