from typing import List
from typing import Set


def reference_descendent(
    current_package: List[str], imports: Set[str], py_package: List[str], py_type: str
) -> str:
    """
    Returns a reference to a python type in a package that is a descendent of the
    current package, and adds the required import that is aliased to avoid name
    conflicts.
    """
    importing_descendent = py_package[len(current_package) :]
    string_from = ".".join(importing_descendent[:-1])
    string_import = importing_descendent[-1]
    if string_from:
        string_alias = "_".join(importing_descendent)
        imports.add(f"from .{string_from} import {string_import} as {string_alias}")
        return f'"{string_alias}.{py_type}"'
    else:
        imports.add(f"from . import {string_import}")
        return f'"{string_import}.{py_type}"'