Passed
Pull Request — master (#17)
by Ramon
50s
created

jsons.deserializers.default_set   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 9
dl 0
loc 20
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A default_set_deserializer() 0 15 2
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