Total Complexity | 1 |
Total Lines | 23 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | #!/usr/bin/python |
||
2 | # -*- coding: utf-8 -*- |
||
3 | |||
4 | import functools |
||
5 | import warnings |
||
6 | |||
7 | |||
8 | def deprecated(func): |
||
9 | """This is a decorator which can be used to mark functions |
||
10 | as deprecated. It will result in a warning being emitted |
||
11 | when the function is used.""" |
||
12 | |||
13 | @functools.wraps(func) |
||
14 | def new_func(*args, **kwargs): |
||
15 | warnings.simplefilter('always', DeprecationWarning) # turn off filter |
||
16 | warnings.warn("Call to deprecated function {}.".format(func.__name__), |
||
17 | category=DeprecationWarning, |
||
18 | stacklevel=2) |
||
19 | warnings.simplefilter('default', DeprecationWarning) # reset filter |
||
20 | return func(*args, **kwargs) |
||
21 | |||
22 | return new_func |
||
23 |