ClassNeedingAFunction.trigger()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nop 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
from typing import Callable
2
3
4
from lagom import Container
5
from lagom.experimental.definitions import PlainFunction
6
7
8
class ClassNeedingAFunction:
9
    def __init__(self, adder: Callable[[int, int], int]):
10
        self.adder = adder
11
12
    def trigger(self, x, y):
13
        adder = self.adder
14
        return adder(x, y)
15
16
17
def add_stuff(x: int, y: int) -> int:
18
    return x + y
19
20
21
def test_ways_of_constructing_functions_can_be_provided(container: Container):
22
    container[Callable[[int, int], int]] = PlainFunction(add_stuff)  # type: ignore
23
    erm = container[ClassNeedingAFunction]
24
    assert erm.trigger(2, 3) == 5
25