| Total Complexity | 2 |
| Total Lines | 20 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | from typing import List |
||
| 2 | from jsons.deserializers import default_list_deserializer |
||
| 3 | |||
| 4 | |||
| 5 | def default_set_deserializer(obj: list, cls: type, **kwargs) -> set: |
||
| 6 | """ |
||
| 7 | Deserialize a (JSON) list into a set by deserializing all items of that |
||
| 8 | list. If the list as a generic type (e.g. Set[datetime]) then it is |
||
| 9 | assumed that all elements can be deserialized to that type. |
||
| 10 | :param obj: the list that needs deserializing. |
||
| 11 | :param cls: the type, optionally with a generic (e.g. Set[str]). |
||
| 12 | :param kwargs: any keyword arguments. |
||
| 13 | :return: a deserialized set instance. |
||
| 14 | """ |
||
| 15 | cls_ = list |
||
| 16 | if hasattr(cls, '__args__'): |
||
| 17 | cls_ = List[cls.__args__[0]] |
||
| 18 | list_ = default_list_deserializer(obj, cls_, **kwargs) |
||
| 19 | return set(list_) |
||
| 20 |