Skip to content

Instantly share code, notes, and snippets.

@technige
Created June 16, 2014 11:31
Show Gist options
  • Save technige/4ac84784ac82ac04bb6e to your computer and use it in GitHub Desktop.
Save technige/4ac84784ac82ac04bb6e to your computer and use it in GitHub Desktop.
def deprecated(message):
""" Decorator for deprecating functions and methods.
::
@deprecated("'foo' has been deprecated in favour of 'bar'")
def foo(x):
pass
"""
def f__(f):
def f_(*args, **kwargs):
warnings.warn(message, category=DeprecationWarning, stacklevel=2)
return f(*args, **kwargs)
f_.__name__ = f.__name__
f_.__doc__ = f.__doc__
f_.__dict__.update(f.__dict__)
return f_
return f__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment