kuon.decorators.deprecated()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 15
ccs 0
cts 7
cp 0
rs 9.9
c 0
b 0
f 0
cc 1
nop 1
crap 2
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