def is_type(var_name, variable, object_type):
    """
    Validates that the provided variable is of the expected type.

    Args:
        var_name (string) - name of the variable (for the exception message)
        variable (object) - the variable to be checked
        object_type (object type) - the expected type, e.g. 'int' or 'float'

    Returns:
        True - if variable value is 'None'
        True - if variable is of expected type. Raises a TypeError exception if not.
    """
    if variable is None:
        return True

    if not isinstance(variable, object_type):
        raise TypeError(
            'Expected value of type {} for "{}", but received "{}" instead.'.format(object_type, var_name, variable))
    else:
        return True