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

lagom.decorators.dependency_definition()   A

Complexity

Conditions 2

Size

Total Lines 11
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2

Importance

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