| Conditions | 3 |
| Total Lines | 19 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | from collections.abc import Mapping |
||
| 9 | def default_mapping_deserializer(obj: dict, cls: type, **kwargs) -> Mapping: |
||
| 10 | """ |
||
| 11 | Deserialize a (JSON) dict into a mapping by deserializing all items of that |
||
| 12 | dict. |
||
| 13 | :param obj: the dict that needs deserializing. |
||
| 14 | :param cls: the type, optionally with a generic (e.g. Set[str]). |
||
| 15 | :param kwargs: any keyword arguments. |
||
| 16 | :return: a deserialized set instance. |
||
| 17 | """ |
||
| 18 | cls_ = Mapping |
||
| 19 | cls_args = get_args(cls) |
||
| 20 | if cls_args: |
||
| 21 | cls_ = MappingType[cls_args] |
||
| 22 | dict_ = default_dict_deserializer(obj, cls_, **kwargs) |
||
| 23 | result = dict_ |
||
| 24 | # Strip any generics from cls to allow for an instance check. |
||
| 25 | if not isinstance(result, get_origin(cls)): |
||
| 26 | result = cls(dict_) |
||
| 27 | return result |
||
| 28 |