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