import types


def asmodule(module):
    """
    Return the module references by `module` name. If `module` is
    already an imported module instance, return it as is.

    """
    if isinstance(module, types.ModuleType):
        return module
    elif isinstance(module, str):
        return __import__(module, fromlist=[""])
    else:
        raise TypeError(type(module))