diff options
author | Olivier Gayot <olivier.gayot@sigexec.com> | 2021-12-23 17:29:48 +0100 |
---|---|---|
committer | Olivier Gayot <olivier.gayot@sigexec.com> | 2021-12-23 23:15:21 +0100 |
commit | 2f2eef5c134eaffbac3db278ba71f153e19de54b (patch) | |
tree | 13269e7400da4f012c14386deeeacf7b5e8276cd /swiftstory/client.py | |
parent | 18f936db51626bd7c35ebc582b623b7b0a9ccdc1 (diff) |
Add type annotations to client.py and game.py
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
Diffstat (limited to 'swiftstory/client.py')
-rw-r--r-- | swiftstory/client.py | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/swiftstory/client.py b/swiftstory/client.py index 9ac08ed..98ba530 100644 --- a/swiftstory/client.py +++ b/swiftstory/client.py @@ -5,6 +5,7 @@ from typing import Optional import websockets.exceptions from swiftstory.game import Game +from swiftstory.game_manager import GameManager from swiftstory.exception import WrongAction, UnsupportedLanguage, JoinError from swiftstory.player import Player @@ -13,14 +14,14 @@ class Client: """ Represent a client. A client manages a (web)socket to communicate with the outside world. It also manages the associated player when in a game. """ - def __init__(self, socket, game_manager): + def __init__(self, socket, game_manager: GameManager) -> None: self.game: Optional[Game] = None - self.game_manager = game_manager + self.game_manager: GameManager = game_manager self.socket = socket self.player: Optional[Player] = None - def join_game(self, game_name, lang) -> str: + def join_game(self, game_name: str, lang: Optional[str]) -> str: if self.game is not None: raise WrongAction('You are already in a game') @@ -39,39 +40,53 @@ class Client: return status - def play_white_card(self, card_id): + def play_white_card(self, card_id: int) -> str: if self.game is None: raise WrongAction('You have to join a game first') + if self.player is None: + raise ValueError("Player is None") return self.game.try_play_card(self.player, card_id) - def pick_black_card(self): + def pick_black_card(self) -> str: if self.game is None: raise WrongAction('You have to join a game first') + if self.player is None: + raise ValueError("Player is None") return self.game.try_become_judge(self.player) - def collect_cards(self): + def collect_cards(self) -> str: if self.game is None: raise WrongAction('You have to join a game first') + if self.player is None: + raise ValueError("Player is None") return self.game.try_collect_cards(self.player) - def designate_card(self, card_id): + def designate_card(self, card_id: int) -> str: if self.game is None: raise WrongAction('You have to join a game first') + if self.player is None: + raise ValueError("Player is None") return self.game.try_designate_card(self.player, card_id) - def view_player_cards(self): + def view_player_cards(self) -> str: if self.game is None: raise WrongAction('You have to join a game first') + if self.player is None: + raise ValueError("Player is None") return self.game.try_view_player_cards(self.player) - def view_played_cards(self): + def view_played_cards(self) -> str: if self.game is None: raise WrongAction('You have to join a game first') + if self.player is None: + raise ValueError("Player is None") return self.game.try_view_played_cards(self.player) - def view_black_card(self): + def view_black_card(self) -> str: if self.game is None: raise WrongAction('You have to join a game first') + if self.player is None: + raise ValueError("Player is None") return self.game.try_view_black_card(self.player) def monitor_player(self) -> None: @@ -87,7 +102,7 @@ class Client: asyncio.create_task(f()) - def disconnect(self): + def disconnect(self) -> None: if self.player is not None: if self.game is None: raise ValueError("Disconnect from inexistent game.") |