from typing import Iterable
from typing import Generator


def _check_type(iterable, name="Unknown"):
    """
    Helper method that checks the input to see if it is iterable as well as not a generator.
    (inputs the iterable as well as the name you want to use for this iterable,
    such as train_inputs, etc.)
    """
    if iterable is not None:
        # type checking to make sure everything is iterable (and warn against generators).
        assert isinstance(iterable, Iterable), "%s is not iterable! Found %s" % \
                                               (name, str(type(iterable)))
        assert not isinstance(iterable, Generator), "%s is a generator! " \
                                                    "Because we loop through the data multiple times, the generator " \
                                                    "will run out after the first iteration. Please consider using " \
                                                    "one of the stream types in opendeep.data.stream instead, " \
                                                    "or define your own class that performs the generator function " \
                                                    "in an __iter__(self) method!" % name
    return iterable