def is_type(valid_type):
    """Returns a validator function that succeeds only for inputs of the provided valid_type.

    :param type valid_type: the type that should be considered valid for the validator
    :returns: a function which returns True its input is an instance of valid_type, and raises TypeError otherwise
    :rtype: callable
    """

    def validate(value, should_raise=True):
        if not isinstance(value, valid_type):
            if should_raise:
                raise TypeError(
                    "Expected value of type {expected}, actual value was of type {actual}.".format(
                        expected=valid_type, actual=type(value)
                    )
                )
            return False
        return True

    return validate