| Conditions | 7 |
| Total Lines | 19 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | # Copyright Pincer 2021-Present |
||
| 20 | def convert( |
||
| 21 | value: Any, |
||
| 22 | factory: Callable[[Any], T], |
||
| 23 | check: Optional[T] = None, |
||
| 24 | client: Optional[Client] = None, |
||
| 25 | ) -> T: |
||
| 26 | def handle_factory() -> T: |
||
| 27 | if check is not None and isinstance(value, check): |
||
| 28 | return value |
||
| 29 | |||
| 30 | try: |
||
| 31 | if client and "_client" in getfullargspec(factory).args: |
||
| 32 | return factory(construct_client_dict(client, value)) |
||
| 33 | except TypeError: # Building type/has no signature |
||
| 34 | pass |
||
| 35 | |||
| 36 | return factory(value) |
||
| 37 | |||
| 38 | return MISSING if value is MISSING else handle_factory() |
||
| 39 |