Conditions | 9 |
Total Lines | 29 |
Code Lines | 22 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | # Copyright Pincer 2021-Present |
||
25 | def convert( |
||
26 | value: Any, |
||
27 | factory: Callable[[Any], T], |
||
28 | check: Optional[T] = None, |
||
29 | client: Optional[Client] = None |
||
30 | ) -> T: |
||
31 | def handle_factory() -> T: |
||
32 | def fin_fac(v: Any): |
||
33 | if is_dataclass(v): |
||
34 | return |
||
35 | |||
36 | if check is not None and isinstance(v, check): |
||
37 | return v |
||
38 | |||
39 | try: |
||
40 | if client and "_client" in getfullargspec(factory).args: |
||
41 | return factory(construct_client_dict(client, v)) |
||
42 | except TypeError: # Building type/has no signature |
||
43 | pass |
||
44 | |||
45 | return factory(v) |
||
46 | |||
47 | return ( |
||
48 | list(map(fin_fac, value)) |
||
49 | if isinstance(value, list) |
||
50 | else fin_fac(value) |
||
51 | ) |
||
52 | |||
53 | return MISSING if value is MISSING else handle_factory() |
||
54 |