Completed
Pull Request — master (#6)
by Steve
02:04
created

lagom.decorators   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 17
dl 0
loc 24
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A bind_to_container() 0 5 1
A dependency_definition() 0 11 2
1 1
import inspect
2
3 1
from .container import Container
4
5
6 1
def bind_to_container(container: Container):
7 1
    def decorator(func):
8 1
        return container.partial(func)
9
10 1
    return decorator
11
12
13 1
def dependency_definition(container: Container):
14 1
    def decorator(func):
15 1
        try:
16 1
            arg_spec = inspect.getfullargspec(func)
17 1
            return_type = arg_spec.annotations["return"]
18 1
        except KeyError:
19 1
            raise SyntaxError("Function used as a definition must have a return type")
20 1
        container.define(return_type, func)
21 1
        return func
22
23
    return decorator
24