Passed
Push — master ( 6cd900...842680 )
by Steve
02:52
created

lagom.updaters   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 91.67%

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 24
ccs 11
cts 12
cp 0.9167
rs 10
c 0
b 0
f 0
wmc 5

2 Functions

Rating   Name   Duplication   Size   Complexity  
A update_container_singletons() 0 10 3
A _define_singleton_in_new_container() 0 5 2
1 1
from typing import List, Type, Union
2
3 1
from lagom.definitions import SingletonWrapper, ConstructionWithoutContainer
4 1
from lagom.interfaces import ExtendableContainer, WriteableContainer, ReadableContainer
5
6
7 1
def update_container_singletons(
8
    container: Union[ExtendableContainer, WriteableContainer], singletons: List[Type]
9
):
10 1
    if isinstance(container, ExtendableContainer):
11 1
        new_container = container.clone()
12
    else:
13
        new_container = container
14 1
    for dep in singletons:
15 1
        _define_singleton_in_new_container(new_container, container, dep)
16 1
    return new_container
17
18
19 1
def _define_singleton_in_new_container(
20
    new_container: WriteableContainer, container: ReadableContainer, dep: Type
21
):
22 1
    new_container[dep] = SingletonWrapper(
23
        ConstructionWithoutContainer(lambda: container.resolve(dep))
24
    )
25