| Total Complexity | 4 |
| Total Lines | 26 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | from typing import Optional, Callable |
||
| 2 | from jsons._main_impl import load |
||
| 3 | |||
| 4 | |||
| 5 | def default_dict_deserializer( |
||
| 6 | obj: dict, |
||
| 7 | cls: type, |
||
| 8 | key_transformer: Optional[Callable[[str], str]] = None, |
||
| 9 | **kwargs) -> dict: |
||
| 10 | """ |
||
| 11 | Deserialize a dict by deserializing all instances of that dict. |
||
| 12 | :param obj: the dict that needs deserializing. |
||
| 13 | :param key_transformer: a function that transforms the keys to a different |
||
| 14 | style (e.g. PascalCase). |
||
| 15 | :param cls: not used. |
||
| 16 | :param kwargs: any keyword arguments. |
||
| 17 | :return: a deserialized dict instance. |
||
| 18 | """ |
||
| 19 | key_transformer = key_transformer or (lambda key: key) |
||
| 20 | kwargs_ = {**{'key_transformer': key_transformer}, **kwargs} |
||
| 21 | if hasattr(cls, '__args__') and len(cls.__args__) > 1: |
||
| 22 | sub_cls = cls.__args__[1] |
||
| 23 | kwargs_['cls'] = sub_cls |
||
| 24 | return {key_transformer(key): load(obj[key], **kwargs_) |
||
| 25 | for key in obj} |
||
| 26 |