from typing import Union
from typing import Callable
from typing import Tuple
from typing import Any
from typing import Dict


def _wrap_function_if_callable(
    fn: Union[str, Callable], args: Tuple[Any, ...] = (), kwargs: Dict[str, Any] = {},
) -> Union[str, Callable]:
    """Wraps a function call with its `args` and `kwargs` into a lambda if
    either is provided. If `fn` is not callable simply returns it.

    Used to properly handle functions with arguments.

    Args:
        fn (function): Function to wrap into a lambda
        args (Tuple[Any, ...]): Positional arguments passed to `fn`. Defaults to `()`.
        kwargs (Dict[str, Any]): Keyword arguments passed to `fn`. Defaults to `{}`.

    Returns:
        Union[str, Callable]: A wrapped function call or `fn`.
    """
    if callable(fn) and (args or kwargs):
        return lambda: fn(*args, **kwargs)
    else:
        return fn