summaryrefslogtreecommitdiff
path: root/swiftstory
diff options
context:
space:
mode:
authorOlivier Gayot <olivier.gayot@sigexec.com>2021-12-23 17:42:57 +0100
committerOlivier Gayot <olivier.gayot@sigexec.com>2021-12-23 23:15:21 +0100
commit0b6991b77fea008163d08ccc1777ac405e2b0a41 (patch)
treed1725c5b6c90f470f90dce65cff9ca88c45aa2c4 /swiftstory
parente9faa90b9e3c8138b5d4763a2d8279f61486238c (diff)
Add type annotations to player.py and status.py
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
Diffstat (limited to 'swiftstory')
-rw-r--r--swiftstory/player.py12
-rw-r--r--swiftstory/status.py5
2 files changed, 9 insertions, 8 deletions
diff --git a/swiftstory/player.py b/swiftstory/player.py
index 011ae51..525a4e6 100644
--- a/swiftstory/player.py
+++ b/swiftstory/player.py
@@ -1,11 +1,11 @@
import asyncio
import json
-from typing import Any
+from typing import Any, Dict, Tuple
class Player:
- def __init__(self):
- self.cards = {}
+ def __init__(self) -> None:
+ self.cards: Dict[int, Tuple[int, str]] = {}
self.next_idx = 0
self.score = 0
@@ -15,17 +15,17 @@ class Player:
self.name = 'default'
self.notifications: asyncio.Queue = asyncio.Queue()
- def pop_card(self, card_id):
+ def pop_card(self, card_id: int) -> Tuple[int, str]:
return self.cards.pop(card_id)
- def inc_score(self):
+ def inc_score(self) -> None:
self.score += 1
self.register_notification({
'op': 'updated_score',
'content': self.score,
})
- def receive_card(self, card):
+ def receive_card(self, card: Tuple[int, str]) -> int:
self.cards[self.next_idx] = card
self.next_idx += 1
return self.next_idx - 1
diff --git a/swiftstory/status.py b/swiftstory/status.py
index fb8347b..d794580 100644
--- a/swiftstory/status.py
+++ b/swiftstory/status.py
@@ -1,8 +1,9 @@
+from typing import Any
import json
-def error(msg, code=255):
+def error(msg: str, code: int = 255) -> str:
return json.dumps({'type': 'response', 'content': {'status': code, 'info': msg}})
-def success(obj):
+def success(obj: Any) -> str:
return json.dumps({'type': 'response', 'content': {'status': 0, 'result': obj}})