code quality (mypy+flake8)

This commit is contained in:
Maxime Réaux 2026-02-04 16:10:53 +01:00
parent 7210ddc927
commit 55abdccc64
19 changed files with 778 additions and 497 deletions

View file

@ -1,21 +1,22 @@
from __future__ import annotations
from uuid import uuid4
from typing import Any, Dict
class Round:
def __init__(self):
def __init__(self) -> None:
self.id: str = str(uuid4())
self.choices: dict[str, Choice] = {}
self.battles: dict[str, Battle] = {}
self.choices: Dict[str, Choice] = {}
self.battles: Dict[str, Battle] = {}
self.is_over: bool = False
def set_id(self, new_id: str):
def set_id(self, new_id: str) -> None:
self.id = new_id
def set_state(self, new_state: bool):
def set_state(self, new_state: bool) -> None:
self.is_over = new_state
def toDict(self):
def toDict(self) -> Dict[str, Any]:
return {
"id": self.id,
# "sectors" : self.sectors,
@ -25,7 +26,7 @@ class Round:
}
@staticmethod
def fromDict(data: dict):
def fromDict(data: Dict[str, Any]) -> Round:
rnd = Round()
rnd.set_id(data["id"])
# rnd.sectors = data.get("sectors", {})
@ -55,13 +56,14 @@ class Round:
priority_sector_id: str | None,
secondary_sector_id: str | None,
comment: str | None,
):
) -> None:
choice = self.get_choice(participant_id)
choice.set_priority(priority_sector_id)
choice.set_secondary(secondary_sector_id)
choice.set_comment(comment)
if choice:
choice.set_priority(priority_sector_id)
choice.set_secondary(secondary_sector_id)
choice.set_comment(comment)
def remove_choice(self, participant_id: str):
def remove_choice(self, participant_id: str) -> None:
del self.choices[participant_id]
# Battle methods
@ -84,16 +86,17 @@ class Round:
score: str | None,
victory_condition: str | None,
comment: str | None,
):
) -> None:
bat = self.get_battle(sector_id)
bat.set_player_1(player_1_id)
bat.set_player_2(player_2_id)
bat.set_winner(winner_id)
bat.set_score(score)
bat.set_victory_condition(victory_condition)
bat.set_comment(comment)
if bat:
bat.set_player_1(player_1_id)
bat.set_player_2(player_2_id)
bat.set_winner(winner_id)
bat.set_score(score)
bat.set_victory_condition(victory_condition)
bat.set_comment(comment)
def remove_battle(self, sector_id: str):
def remove_battle(self, sector_id: str) -> None:
del self.battles[sector_id]
@ -113,16 +116,16 @@ class Choice:
)
self.comment: str | None = None
def set_id(self, new_id: str):
def set_id(self, new_id: str) -> None:
self.participant_id = new_id
def set_priority(self, new_priority_id: str):
def set_priority(self, new_priority_id: str | None) -> None:
self.priority_sector_id = new_priority_id
def set_secondary(self, new_secondary_id: str):
def set_secondary(self, new_secondary_id: str | None) -> None:
self.secondary_sector_id = new_secondary_id
def set_comment(self, new_comment: str):
def set_comment(self, new_comment: str | None) -> None:
self.comment = new_comment
@ -141,23 +144,23 @@ class Battle:
self.victory_condition: str | None = None
self.comment: str | None = None
def set_id(self, new_id: str):
def set_id(self, new_id: str) -> None:
self.sector_id = new_id
def set_player_1(self, new_player_id: str):
def set_player_1(self, new_player_id: str | None) -> None:
self.player_1_id = new_player_id
def set_player_2(self, new_player_id: str):
def set_player_2(self, new_player_id: str | None) -> None:
self.player_2_id = new_player_id
def set_winner(self, new_player_id: str):
def set_winner(self, new_player_id: str | None) -> None:
self.winner_id = new_player_id
def set_score(self, new_score: str):
def set_score(self, new_score: str | None) -> None:
self.score = new_score
def set_victory_condition(self, new_victory_condition: str):
def set_victory_condition(self, new_victory_condition: str | None) -> None:
self.victory_condition = new_victory_condition
def set_comment(self, new_comment: str):
def set_comment(self, new_comment: str | None) -> None:
self.comment = new_comment