from typing import Set
from typing import Dict
from typing import List


def _find_all_top_modules(
    used_modules: Set[str], pkged_module_dependencies_data: Dict[str, List[str]]
) -> Set[str]:
    """Given the dependency information about packaged modules, find the modules
    that do are not a dependency for another module. This represent the set of modules
    that must explicitly be packaged if used by a function.

    Args:
        used_modules (Set[str]): modules directly imported
        pkged_module_dependencies_data (Dict[str, List[str]])

    Returns:
        Set[str]: Modules that are not a dependency for another module
    """

    all_modules_names = set(used_modules)

    for _, dependencies in list(
        filter(lambda k: k[0] in used_modules, pkged_module_dependencies_data.items())
    ):

        for dependency in dependencies:
            try:
                all_modules_names.remove(dependency)
            except Exception as e:
                pass

    return all_modules_names