From cf343c21a89455a7f2d0c5979ab6ccb17e1ad1cc Mon Sep 17 00:00:00 2001 From: Calum Lind Date: Tue, 8 Nov 2016 18:27:46 +0000 Subject: [PATCH] [Base] Add new deprecated decorator --- deluge/decorators.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/deluge/decorators.py b/deluge/decorators.py index f1b3a24ba..c00da58a9 100644 --- a/deluge/decorators.py +++ b/deluge/decorators.py @@ -9,6 +9,7 @@ import inspect import re +import warnings from functools import wraps @@ -114,3 +115,21 @@ def _overrides(stack, method, explicit_base_classes=None): raise Exception('Function override "%s" not found in any superclass: %s\n%s' % (method.__name__, check_classes, 'File: %s:%s' % (stack[1][1], stack[1][2]))) return method + + +def deprecated(func): + """This is a decorator which can be used to mark function as deprecated. + + It will result in a warning being emmitted when the function is used. + + """ + + @wraps(func) + def depr_func(*args, **kwargs): + warnings.simplefilter('always', DeprecationWarning) # Turn off filter + warnings.warn('Call to deprecated function {}.'.format(func.__name__), + category=DeprecationWarning, stacklevel=2) + warnings.simplefilter('default', DeprecationWarning) # Reset filter + return func(*args, **kwargs) + + return depr_func