from typing import Callable
import functools
from typing import Any
import warnings


def deprecated(func: Callable) -> Callable:
    """Decorator that can be used to mark functions as deprecated, emitting a warning
    when the function is used.

    Arguments:
        func:
            The function to be decorated.

    Returns:
        The decorated function, which emits a warning when used.
    """

    @functools.wraps(func)
    def wrapper(*args, **kwargs) -> Any:
        """Wrapped function to be returned by the decorator.

        Returns:
            The original function evaluation.
        """
        warnings.simplefilter("always", DeprecationWarning)  # turn off filter
        warnings.warn(
            "Deprecated function {} invoked".format(func.__name__),
            category=DeprecationWarning,
            stacklevel=2,
        )
        warnings.simplefilter("default", DeprecationWarning)  # reset filter
        return func(*args, **kwargs)

    return wrapper