Passed
Pull Request — master (#101)
by Simon
12:36
created

hyperactive.experiment._utility   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 29
rs 10
c 0
b 0
f 0
wmc 5

2 Functions

Rating   Name   Duplication   Size   Complexity  
A add_callback() 0 13 3
A add_catch() 0 13 2
1
def add_callback(before=None, after=None):
2
    def decorator(function):
3
        def wrapper(self, param):
4
            if before:
5
                [before_callback(self, param) for before_callback in before]
6
            result = function(self, param)
7
            if after:
8
                [after_callback(self, param) for after_callback in after]
9
            return result
10
11
        return wrapper
12
13
    return decorator
14
15
16
def add_catch(catch):
17
    def decorator(function):
18
        def wrapper(self, param):
19
            try:
20
                result = function(self, param)
21
            except tuple(catch.keys()) as e:
22
                result = catch[e.__class__]
23
24
            return result
25
26
        return wrapper
27
28
    return decorator
29