models.user   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 67
dl 0
loc 76
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A Stats.from_dict() 0 11 2
A User.from_dict() 0 27 2

1 Function

Rating   Name   Duplication   Size   Complexity  
A user_from_dict() 0 2 1
1
from dataclasses import dataclass
2
from typing import Any, Optional
3
from models import from_int, from_str, from_union, from_none, from_bool
4
5
6
@dataclass
7
class Stats:
8
    joined: int
9
    first: int
10
    second: int
11
    third: int
12
    forfeits: int
13
    dqs: int
14
15
    @staticmethod
16
    def from_dict(obj: Any) -> 'Stats':
17
        if not isinstance(obj, dict):
18
            return None
19
        joined = from_int(obj.get("joined"))
20
        first = from_int(obj.get("first"))
21
        second = from_int(obj.get("second"))
22
        third = from_int(obj.get("third"))
23
        forfeits = from_int(obj.get("forfeits"))
24
        dqs = from_int(obj.get("dqs"))
25
        return Stats(joined, first, second, third, forfeits, dqs)
26
27
28
@dataclass
29
class User:
30
    id: str
31
    full_name: str
32
    name: str
33
    url: str
34
    discriminator: Optional[str] = None
35
    stats: Optional[Stats] = None
36
    pronouns: Optional[str] = None
37
    flair: Optional[str] = None
38
    twitch_name: Optional[str] = None
39
    twitch_display_name: Optional[str] = None
40
    twitch_channel: Optional[str] = None
41
    can_moderate: Optional[bool] = None
42
    avatar: Optional[str] = None
43
44
    @staticmethod
45
    def from_dict(obj: Any) -> 'User':
46
        if not isinstance(obj, dict):
47
            return None
48
        id = from_str(obj.get("id"))
49
        full_name = from_str(obj.get("full_name"))
50
        name = from_str(obj.get("name"))
51
        discriminator = from_union(
52
            [from_str, from_none], obj.get("discriminator"))
53
        url = from_str(obj.get("url"))
54
        avatar = from_union([from_str, from_none], obj.get("avatar"))
55
        pronouns = from_union([from_str, from_none], obj.get("pronouns"))
56
        flair = from_union([from_str, from_none], obj.get("flair"))
57
        twitch_name = from_union([from_str, from_none], obj.get("twitch_name"))
58
        twitch_display_name = from_union(
59
            [from_str, from_none], obj.get("twitch_display_name"))
60
        twitch_channel = from_union(
61
            [from_str, from_none], obj.get("twitch_channel"))
62
        can_moderate = from_union(
63
            [from_bool, from_none], obj.get("can_moderate"))
64
        stats = from_union([Stats.from_dict, from_none], obj.get("stats"))
65
        return User(
66
            id=id, full_name=full_name, name=name, discriminator=discriminator,
67
            url=url, avatar=avatar, pronouns=pronouns, flair=flair,
68
            twitch_name=twitch_name, twitch_display_name=twitch_display_name,
69
            twitch_channel=twitch_channel, can_moderate=can_moderate,
70
            stats=stats
71
        )
72
73
74
def user_from_dict(s: Any) -> User:
75
    return User.from_dict(s)
76