from typing import Callable
from typing import Any
import importlib


def get_function_by_name(func_str: str) -> Callable[..., Any]:
    """Get a function by its name.

    Args:
        func_str (str): Name of function including module,
            like 'tensorflow.nn.softplus'.

    Returns:
        Callable[Any]: the function.

    Raises:
        KeyError: Function does not exists.

    """
    module_name, _, func_name = func_str.rpartition(".")
    if module_name:
        module = importlib.import_module(module_name)
        return getattr(module, func_name)
    return globals()[func_name]