Conditions | 6 |
Total Lines | 27 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | # Copyright Pincer 2021-Present |
||
26 | def convert( |
||
27 | value: Any, |
||
28 | factory: Callable[[Any], T], |
||
29 | check: Optional[type] = None, |
||
30 | client: Optional[Client] = None |
||
31 | ) -> T: |
||
32 | """ |
||
33 | Convert a value to T if its not MISSING. |
||
34 | """ |
||
35 | |||
36 | def handle_factory() -> T: |
||
37 | def fin_fac(v: Any): |
||
38 | if check is not None and isinstance(v, check): |
||
39 | return v |
||
40 | |||
41 | if client is None: |
||
42 | return factory(v) |
||
43 | |||
44 | return factory(construct_client_dict(client, v)) |
||
45 | |||
46 | return ( |
||
47 | list(map(fin_fac, value)) |
||
48 | if isinstance(value, list) |
||
49 | else fin_fac(value) |
||
50 | ) |
||
51 | |||
52 | return MISSING if value is MISSING else handle_factory() |
||
53 |