def lazify_imports(
    registry: dict[str, str],
    package: str,
    fallback: Callable | None = None,
) -> tuple[tuple[str, ...], Callable, Callable]:
    """Leverage PEP 562 to make imports lazy in an __init__.py

    The registry must be a dictionary with the items to import as keys and the
    modules they belong to as a value.
    """
    __all__ = tuple(registry.keys())

    def __dir__() -> tuple[str, ...]:  # noqa: N807
        return __all__

    def __getattr__(name: str) -> Any:  # noqa: N807
        if name not in registry:
            raise AttributeError
        module_path = f"{package}.{registry[name]}"
        return import_class(module_path, name, fallback=fallback)

    return __all__, __dir__, __getattr__
Leverage PEP 562 to make imports lazy in an __init__.py

    The registry must be a dictionary with the items to import as keys and the
    modules they belong to as a value.
    
libqtile/utils.py