Total Complexity | 3 |
Total Lines | 25 |
Duplicated Lines | 56 % |
Changes | 0 |
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 |
|
|
|||
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 |