Created
November 23, 2023 15:35
-
-
Save ZoltonMD/ed334a99c65922624e43e16e80554e76 to your computer and use it in GitHub Desktop.
Deprecation wrapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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