Skip to content

Instantly share code, notes, and snippets.

@premchalmeti
Created August 28, 2021 13:54
Show Gist options
  • Save premchalmeti/3f2b3f77e77149e94c3fa32a6bc2bd1e to your computer and use it in GitHub Desktop.
Save premchalmeti/3f2b3f77e77149e94c3fa32a6bc2bd1e to your computer and use it in GitHub Desktop.
Decorator to deprecate function with optional warning msg
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