summaryrefslogtreecommitdiff
path: root/swiftstory/interface/ws.py
diff options
context:
space:
mode:
authorOlivier Gayot <olivier.gayot@sigexec.com>2021-12-29 17:05:21 +0100
committerOlivier Gayot <olivier.gayot@sigexec.com>2021-12-29 17:06:29 +0100
commit95ca11e98c47c3e8e57093c37134a6f51bcb6f30 (patch)
tree4c10504aee30dab96e6d5836f0f35f9d6a6a9810 /swiftstory/interface/ws.py
parent8d242a5e6c090ee8165b36fea6520d533269518e (diff)
Add type hinting everywhere so we can enable strict mypy options
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
Diffstat (limited to 'swiftstory/interface/ws.py')
-rw-r--r--swiftstory/interface/ws.py11
1 files changed, 6 insertions, 5 deletions
diff --git a/swiftstory/interface/ws.py b/swiftstory/interface/ws.py
index 2485b4f..a86c730 100644
--- a/swiftstory/interface/ws.py
+++ b/swiftstory/interface/ws.py
@@ -1,6 +1,7 @@
import contextlib
import json
import logging
+from typing import Union
import websockets.exceptions
from websockets.server import WebSocketServerProtocol
@@ -16,7 +17,7 @@ class WebsocketsInterface:
def __init__(self, game_manager: GameManager):
self.game_manager = game_manager
- async def connection_handler(self, websocket: WebSocketServerProtocol, path: str):
+ async def connection_handler(self, websocket: WebSocketServerProtocol, path: str) -> None:
client = Client(websocket, self.game_manager)
with contextlib.suppress(websockets.exceptions.ConnectionClosed):
@@ -25,8 +26,8 @@ class WebsocketsInterface:
client.disconnect()
- def message_received_handler(self, client, message):
- def join_game():
+ def message_received_handler(self, client: Client, message: Union[bytes, str]) -> str:
+ def join_game() -> str:
try:
game_name = json_msg['game_name']
except KeyError:
@@ -35,7 +36,7 @@ class WebsocketsInterface:
lang = json_msg.get('lang')
return client.join_game(game_name, lang)
- def designate_card():
+ def designate_card() -> str:
card_id = None
try:
card_id = int(json_msg['card_id'])
@@ -44,7 +45,7 @@ class WebsocketsInterface:
finally:
return client.designate_card(card_id)
- def play_white_card():
+ def play_white_card() -> str:
try:
card_id = int(json_msg['card_id'])
except KeyError: