from typing import Union
from typing import Callable


def _pick_func(**kwargs: Union[str, Callable, None]) -> Union[str, Callable]:
    """Extracts the exactly *one* function from the provided arguments.

    Raises an error if either zero or more than one functions is passed.
    Uses the names of the arguments as part of the error message.
    """

    result: Union[str, Callable, None] = None
    count = 0

    for val in kwargs.values():
        if val:
            result = val
            count += 1

    if count != 1:
        names = ", ".join(kwargs)
        raise TypeError(f"exactly 1 of [{names}] must be provided")
    if not callable(result) and type(result) != str or not result:
        raise TypeError(
            "provided function must be a callable or the str name of a UDF, "
            f"not {type(result)}"
        )
    return result