from inspect import getmodule


def __is_defined_in_submodule(submodule_name_prefix, x):
    """
    Utility method to return True if x is not a module and its module name starts with submodule_name_prefix
    e.g. 'autoclass.autohash_'.

    :param submodule_name_prefix:
    :param x:
    :return:
    """
    # if _inspect.ismodule(x):
    #     return False
    # else:
    m = getmodule(x)
    if m is None:
        return True
    elif hasattr(m, '__name__') and m.__name__.startswith(submodule_name_prefix):
        return True
    else:
        return False