Skip to content

Instantly share code, notes, and snippets.

@lvidarte
Created June 30, 2010 14:05
Show Gist options
  • Save lvidarte/458694 to your computer and use it in GitHub Desktop.
Save lvidarte/458694 to your computer and use it in GitHub Desktop.
deprecated decorator
import warnings
def deprecated(func):
def new_func(*args, **kwargs):
warnings.warn('This function is deprecated', DeprecationWarning, 2)
return func(*args, **kwargs)
return new_func
@deprecated
def sum(a, b):
return a + b
r = sum(1, 2)
print r
@lvidarte
Copy link
Author

/home/xleo/workspace/ptest/src/test.py:21: DeprecationWarning: This function is deprecated
  r = sum(1, 2)
3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment