Completed
Pull Request — master (#6)
by Steve
02:17 queued 32s
created

lagom.decorators.bind_to_container()   A

Complexity

Conditions 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

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