models.user_past_races   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 56 %

Importance

Changes 0
Metric Value
wmc 3
eloc 20
dl 14
loc 25
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A UserPastRaces.from_dict() 8 8 2

1 Function

Rating   Name   Duplication   Size   Complexity  
A user_past_races_from_dict() 0 2 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
from dataclasses import dataclass
2
from typing import Any, List
3
from models import from_int, from_list
4
from models.race import Race
5
6
7 View Code Duplication
@dataclass
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
8
class UserPastRaces:
9
    count: int
10
    num_pages: int
11
    races: List[Race]
12
13
    @staticmethod
14
    def from_dict(obj: Any) -> 'UserPastRaces':
15
        if not isinstance(obj, dict):
16
            return None
17
        count = from_int(obj.get("count"))
18
        num_pages = from_int(obj.get("num_pages"))
19
        races = from_list(Race.from_dict, obj.get("races"))
20
        return UserPastRaces(count, num_pages, races)
21
22
23
def user_past_races_from_dict(s: Any) -> UserPastRaces:
24
    return UserPastRaces.from_dict(s)
25