| Conditions | 6 |
| Total Lines | 74 |
| Code Lines | 74 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | from dataclasses import dataclass |
||
| 158 | @staticmethod |
||
| 159 | def from_dict(obj: Any) -> 'Race': |
||
| 160 | if not isinstance(obj, dict): |
||
| 161 | return None |
||
| 162 | name = from_str(obj.get("name")) |
||
| 163 | slug = from_str(obj.get("slug")) |
||
| 164 | status = Status.from_dict(obj.get("status")) |
||
| 165 | url = from_str(obj.get("url")) |
||
| 166 | data_url = from_str(obj.get("data_url")) |
||
| 167 | websocket_url = from_union( |
||
| 168 | [from_str, from_none], obj.get("websocket_url")) |
||
| 169 | websocket_bot_url = from_union( |
||
| 170 | [from_str, from_none], obj.get("websocket_bot_url")) |
||
| 171 | websocket_oauth_url = from_union( |
||
| 172 | [from_str, from_none], obj.get("websocket_oauth_url")) |
||
| 173 | category = RaceCategory.from_dict(obj.get("category")) |
||
| 174 | goal = Goal.from_dict(obj.get("goal")) |
||
| 175 | info = from_str(obj.get("info")) |
||
| 176 | entrants_count = from_int(obj.get("entrants_count")) |
||
| 177 | entrants_count_inactive = from_int(obj.get("entrants_count_inactive")) |
||
| 178 | entrants = from_union([lambda x: from_list( |
||
| 179 | Entrant.from_dict, x), from_none], obj.get("entrants")) |
||
| 180 | opened_at = from_datetime(obj.get("opened_at")) |
||
| 181 | start_delay = from_union( |
||
| 182 | [from_timedelta, from_none], obj.get("start_delay")) |
||
| 183 | started_at = from_union( |
||
| 184 | [from_datetime, from_none], (obj.get("started_at"))) |
||
| 185 | ended_at = from_union([from_datetime, from_none], |
||
| 186 | (obj.get("ended_at"))) |
||
| 187 | cancelled_at = from_union( |
||
| 188 | [from_datetime, from_none], (obj.get("cancelled_at"))) |
||
| 189 | unlisted = from_union([from_bool, from_none], obj.get("unlisted")) |
||
| 190 | time_limit = from_timedelta(obj.get("time_limit")) |
||
| 191 | streaming_required = from_union( |
||
| 192 | [from_bool, from_none], obj.get("streaming_required")) |
||
| 193 | auto_start = from_union([from_bool, from_none], obj.get("auto_start")) |
||
| 194 | opened_by = from_union( |
||
| 195 | [lambda x: User.from_dict(x), from_none], obj.get("opened_by")) |
||
| 196 | monitors = from_union([lambda x: from_list( |
||
| 197 | User.from_dict, x), from_none], obj.get("monitors")) |
||
| 198 | recordable = from_union([from_bool, from_none], obj.get("recordable")) |
||
| 199 | recorded = from_union([from_bool, from_none], obj.get("recorded")) |
||
| 200 | recorded_by = from_union( |
||
| 201 | [lambda x: User.from_dict(x), from_none], obj.get("recorded_by")) |
||
| 202 | allow_comments = from_union( |
||
| 203 | [from_bool, from_none], obj.get("allow_comments")) |
||
| 204 | hide_comments = from_union( |
||
| 205 | [from_bool, from_none], obj.get("hide_comments")) |
||
| 206 | allow_midrace_chat = from_union( |
||
| 207 | [from_bool, from_none], obj.get("allow_midrace_chat")) |
||
| 208 | allow_non_entrant_chat = from_union( |
||
| 209 | [from_bool, from_none], obj.get("allow_non_entrant_chat")) |
||
| 210 | chat_message_delay = from_union( |
||
| 211 | [from_str, from_none], obj.get("chat_message_delay")) |
||
| 212 | version = from_union([from_int, from_none], obj.get("version")) |
||
| 213 | entrants_count_finished = from_union( |
||
| 214 | [from_int, from_none], obj.get("entrants_count_finished")) |
||
| 215 | return Race( |
||
| 216 | name=name, status=status, url=url, data_url=data_url, |
||
| 217 | websocket_url=websocket_url, websocket_bot_url=websocket_bot_url, |
||
| 218 | websocket_oauth_url=websocket_oauth_url, category=category, |
||
| 219 | goal=goal, info=info, entrants_count=entrants_count, |
||
| 220 | entrants_count_inactive=entrants_count_inactive, |
||
| 221 | opened_at=opened_at, time_limit=time_limit, entrants=entrants, |
||
| 222 | version=version, started_at=started_at, ended_at=ended_at, |
||
| 223 | cancelled_at=cancelled_at, unlisted=unlisted, |
||
| 224 | streaming_required=streaming_required, auto_start=auto_start, |
||
| 225 | opened_by=opened_by, monitors=monitors, recordable=recordable, |
||
| 226 | recorded=recorded, recorded_by=recorded_by, |
||
| 227 | allow_comments=allow_comments, hide_comments=hide_comments, |
||
| 228 | allow_midrace_chat=allow_midrace_chat, |
||
| 229 | allow_non_entrant_chat=allow_non_entrant_chat, |
||
| 230 | chat_message_delay=chat_message_delay, start_delay=start_delay, |
||
| 231 | entrants_count_finished=entrants_count_finished, slug=slug |
||
| 232 | ) |
||
| 246 |