import functools
import warnings


def deprecated(message = "Function %s is now deprecated"):
    """
    Decorator that marks a certain function or method as
    deprecated so that whenever such function is called
    an output messaged warns the developer about the
    deprecation (incentive).

    :type message: String
    :param message: The message template to be used in the
    output operation of the error.
    :rtype: Decorator
    :return: The decorator that should be used to wrap a
    function and mark it as deprecated (send warning).
    """

    def decorator(function):

        name = function.__name__ if hasattr(function, "__name__") else None

        @functools.wraps(function)
        def interceptor(*args, **kwargs):
            warnings.simplefilter("always", DeprecationWarning)
            warnings.warn(
                message % name,
                category = DeprecationWarning,
                stacklevel = 2
            )
            warnings.simplefilter("default", DeprecationWarning)
            return function(*args, **kwargs)

        return interceptor

    return decorator