from typing import Union
from typing import List


def generic_import(name: Union[str, List[str]]):
    """
    Import using string or list of module names
    """
    if isinstance(name, str):
        components = name.split('.')
    else:
        assert isinstance(name, list), name
        components = name

    mod = None
    for i, comp in enumerate(components):
        try:
            # if imported sucessfully __import__ returns a top module
            mod = __import__('.'.join(components[:i + 1]))
        except ModuleNotFoundError:
            for comp in components[1:]:
                try:
                    mod = getattr(mod, comp)
                except AttributeError:
                    raise
    return mod