Total Complexity | 4 |
Total Lines | 25 |
Duplicated Lines | 0 % |
Changes | 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 |