diff options
author | Olivier Gayot <olivier.gayot@sigexec.com> | 2021-12-23 15:47:13 +0100 |
---|---|---|
committer | Olivier Gayot <olivier.gayot@sigexec.com> | 2021-12-23 23:15:21 +0100 |
commit | 96eaa6555ae44e30b3784576a6ecd0941523691f (patch) | |
tree | 4fa06a1a7c1b434085f2e015b5928bd91be01cd8 | |
parent | c8d99bb33f21991a6c3e7539806f2bc73659b896 (diff) |
Add required annotations to make sure mypy succeeds
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
-rw-r--r-- | swiftstory/client.py | 6 | ||||
-rw-r--r-- | swiftstory/game.py | 5 | ||||
-rw-r--r-- | swiftstory/game_manager.py | 3 |
3 files changed, 11 insertions, 3 deletions
diff --git a/swiftstory/client.py b/swiftstory/client.py index 3000b79..52957c2 100644 --- a/swiftstory/client.py +++ b/swiftstory/client.py @@ -1,14 +1,16 @@ import asyncio import logging +from typing import Optional import websockets +from swiftstory.game import Game from swiftstory.exception import WrongAction, UnsupportedLanguage, JoinError class Client: def __init__(self, socket, game_manager): - self.game = None + self.game: Optional[Game] = None self.game_manager = game_manager self.socket = socket @@ -75,4 +77,6 @@ class Client: def disconnect(self): if self.player is not None: + if self.game is None: + raise ValueError("Disconnect from inexistent game.") self.game.disconnect(self.player) diff --git a/swiftstory/game.py b/swiftstory/game.py index cda3ddd..20ac726 100644 --- a/swiftstory/game.py +++ b/swiftstory/game.py @@ -1,4 +1,5 @@ import random +from typing import Optional from swiftstory.exception import WrongAction, JoinError from swiftstory.player import Player @@ -19,7 +20,7 @@ class Game: self.players = [] - self.judge = None + self.judge: Optional[Player] = None self.board = Board() self.board.white_pick = white_pick @@ -101,6 +102,8 @@ class Game: self.board.play_card(player, card) + if self.judge is None: + raise ValueError("There is no judge") self.judge.register_notification({'op': 'card_played'}) return success({'card_id': card_id}) diff --git a/swiftstory/game_manager.py b/swiftstory/game_manager.py index a87f67e..e7b3305 100644 --- a/swiftstory/game_manager.py +++ b/swiftstory/game_manager.py @@ -1,5 +1,6 @@ import logging import os +from typing import Dict, List from swiftstory.exception import UnsupportedLanguage from swiftstory.game import Game @@ -8,7 +9,7 @@ from swiftstory.cards import Cards class GameManager: def __init__(self): - self.langs = {} + self.langs: Dict[str, dict] = {} for filename in next(os.walk('usr/share/swiftstory/lang'))[1]: self.langs[filename] = {} |