def assert_is_list_of(value, cls, min=None, max=None):
    """
    If value is not a list of cls instances, raises TypeError.
    """
    if not isinstance(value, list):
        raise TypeError('Must be list of {}'.format(cls.__name__))
    for item in value:
        if not isinstance(item, cls):
            raise TypeError('Must be list of {}'.format(cls.__name__))
        if min is not None and item < min or max is not None and item > max:
            raise ValueError('All values must be in range {} to {}'.format(
                min, max))
