Skip to content

Instantly share code, notes, and snippets.

@tlatsas
Last active December 21, 2015 14:18
Show Gist options
  • Save tlatsas/6318355 to your computer and use it in GitHub Desktop.
Save tlatsas/6318355 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import functools
import warnings
warnings.simplefilter("once", category=(PendingDeprecationWarning, DeprecationWarning))
def deprecate(msg, klass=PendingDeprecationWarning):
def decorator(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
warnings.warn(msg, klass, stacklevel=2)
return func(*args, **kwargs)
return wrapper
return decorator
@deprecate("This function will be deprecated in the future")
def old_function(a, b):
new_function(a, b, 0)
def new_function(a, b, c):
print(a+b+c)
if __name__ == "__main__":
old_function(1, 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment