Skip to content

Instantly share code, notes, and snippets.

@ZoltonMD
Created November 23, 2023 15:35
Show Gist options
  • Save ZoltonMD/ed334a99c65922624e43e16e80554e76 to your computer and use it in GitHub Desktop.
Save ZoltonMD/ed334a99c65922624e43e16e80554e76 to your computer and use it in GitHub Desktop.
Deprecation wrapper
import warnings
def deprecated(message: str):
""" To decorate deprecated functions/methods
Args:
message (str): Warning message for developers
Returns:
func()
Examples:
>>> @deprecated("Don't use it por favor")
>>> def test():
>>> pass
"""
def deprecated_decorator(func):
def deprecated_func(*args, **kwargs):
warnings.warn("{} is a deprecated function. {}".format(func.__name__, message),
category=DeprecationWarning,
stacklevel=2)
warnings.simplefilter('default', DeprecationWarning)
return func(*args, **kwargs)
return deprecated_func
return deprecated_decorator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment