Created
December 26, 2013 10:28
-
-
Save douglarek/8132040 to your computer and use it in GitHub Desktop.
This file contains 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
import warnings | |
def deprecated(func): | |
"""This is a decorator which can be used to mark functions | |
as deprecated. It will result in a warning being emmitted | |
when the function is used.""" | |
def new_func(*args, **kwargs): | |
#warnings.warn("Call to deprecated function %s." % func.__name__, | |
# category=UserWarning, stacklevel=2) | |
warnings.warn("Call to deprecated function %s." % func.__name__, | |
stacklevel=2) | |
return func(*args, **kwargs) | |
new_func.__name__ = func.__name__ | |
new_func.__doc__ = func.__doc__ | |
new_func.__dict__.update(func.__dict__) | |
return new_func | |
# === Examples of use === | |
@deprecated | |
def some_old_function(x,y): | |
return x + y | |
class SomeClass: | |
@deprecated | |
def some_old_method(self, x,y): | |
return x + y | |
print some_old_function(4, 5) | |
#import warnings | |
# | |
#warnings.simplefilter('once', UserWarning) | |
# | |
#warnings.warn('This is a warning!') | |
#warnings.warn('This is a warning!') | |
#warnings.warn('This is a warning!') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment