kuon.decorators   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 1
eloc 13
dl 0
loc 22
ccs 0
cts 9
cp 0
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A deprecated() 0 15 1
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