Completed
Push — master ( 72b331...d4b7d2 )
by Steffen
02:14
created

kuon.decorators   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 13
dl 0
loc 23
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
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