Created
August 28, 2021 13:54
-
-
Save premchalmeti/3f2b3f77e77149e94c3fa32a6bc2bd1e to your computer and use it in GitHub Desktop.
Decorator to deprecate function with optional warning msg
This file contains hidden or 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
def deprecated(msg=None): | |
def wrapped(func): | |
def inner(*args, **kwargs): | |
import warnings; | |
warnings.simplefilter('always', DeprecationWarning) | |
warnings.warn( | |
msg or '%s() is deprecated' % func.__name__, | |
category=DeprecationWarning | |
) | |
warnings.simplefilter('default', DeprecationWarning) | |
return func(*args, **kwargs) | |
return inner | |
return wrapped |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment