| Conditions | 3 |
| Total Lines | 20 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | from collections import Mapping |
||
| 6 | def default_mapping_deserializer(obj: Mapping, cls: type, **kwargs) -> Mapping: |
||
| 7 | """ |
||
| 8 | Deserialize a (JSON) list into a set by deserializing all items of that |
||
| 9 | list. If the list as a generic type (e.g. Set[datetime]) then it is |
||
| 10 | assumed that all elements can be deserialized to that type. |
||
| 11 | :param obj: the list that needs deserializing. |
||
| 12 | :param cls: the type, optionally with a generic (e.g. Set[str]). |
||
| 13 | :param kwargs: any keyword arguments. |
||
| 14 | :return: a deserialized set instance. |
||
| 15 | """ |
||
| 16 | cls_ = Mapping |
||
| 17 | if hasattr(cls, '__args__'): |
||
| 18 | cls_ = MappingType[cls.__args__] |
||
| 19 | dict_ = default_dict_deserializer(obj, cls_, **kwargs) |
||
| 20 | result = dict_ |
||
| 21 | # Strip any generics from cls to allow for an instance check. |
||
| 22 | stripped_cls = getattr(cls, '__extra__', cls) |
||
| 23 | if not isinstance(result, stripped_cls): |
||
| 24 | result = cls(dict_) |
||
| 25 | return result |
||
| 26 |