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

_define_singleton_in_new_container()   A

Complexity

Conditions 2

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

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