Skip to content

Commit 1c1f5b8

Browse files
committed
TASK: Add static type definitions
1 parent 744bc63 commit 1c1f5b8

File tree

4 files changed

+27
-27
lines changed

4 files changed

+27
-27
lines changed

database/db_wrapper.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def __init__(self):
2323
self.connection.text_factory = lambda x: str(x, 'utf-8', "ignore")
2424
self.cursor = self.connection.cursor()
2525

26-
def create_database(self, database_path):
26+
def create_database(self, database_path: str) -> None:
2727
# Create database file and add admin and users table to the database
2828
open(database_path, 'a').close()
2929

@@ -51,57 +51,57 @@ def create_database(self, database_path):
5151
connection.commit()
5252
connection.close()
5353

54-
def get_user(self, user_id):
54+
def get_user(self, user_id: int) -> tuple:
5555
self.cursor.execute("SELECT * FROM users WHERE userID=?;", [str(user_id)])
5656

5757
result = self.cursor.fetchone()
5858
if len(result) > 0:
5959
return result
6060
else:
61-
return []
61+
return ()
6262

63-
def get_played_games(self, user_id):
63+
def get_played_games(self, user_id: int) -> int:
6464
self.cursor.execute("SELECT gamesPlayed FROM users WHERE userID=?;", [str(user_id)])
6565

6666
result = self.cursor.fetchone()
6767
if len(result) > 0:
68-
return result[0]
68+
return int(result[0])
6969
else:
7070
return 0
7171

72-
def get_all_users(self):
72+
def get_all_users(self) -> list:
7373
self.cursor.execute("SELECT rowid, * FROM users;")
7474
return self.cursor.fetchall()
7575

76-
def get_admins(self):
76+
def get_admins(self) -> list:
7777
self.cursor.execute("SELECT userID from admins;")
7878
admins = self.cursor.fetchall()
7979
admin_list = []
8080
for admin in admins:
8181
admin_list.append(admin[0])
8282
return admin_list
8383

84-
def get_lang_id(self, user_id):
84+
def get_lang_id(self, user_id: int) -> str:
8585
self.cursor.execute("SELECT languageID FROM users WHERE userID=?;", [str(user_id)])
8686
result = self.cursor.fetchone()
8787
if result:
8888
return result[0]
8989
else:
9090
return "en"
9191

92-
def add_user(self, user_id, lang_id, first_name, last_name, username):
92+
def add_user(self, user_id: int, lang_id: str, first_name: str, last_name: str, username: str) -> None:
9393
try:
94-
self.cursor.execute("INSERT INTO users VALUES (?, ?, ?, ?, ?, 0, 0, 0, 0);", (str(user_id), str(lang_id), str(first_name), str(last_name), str(username)))
94+
self.cursor.execute("INSERT INTO users VALUES (?, ?, ?, ?, ?, 0, 0, 0, 0);", (str(user_id), lang_id, first_name, last_name, username))
9595
self.connection.commit()
9696
except sqlite3.IntegrityError:
9797
pass
9898

99-
def insert(self, column_name, value, user_id):
100-
self.cursor.execute("UPDATE users SET " + str(column_name) + "= ? WHERE userID = ?;",
101-
[str(value), str(user_id)])
99+
def insert(self, column_name: str, value: str, user_id: int) -> None:
100+
self.cursor.execute("UPDATE users SET " + column_name + "= ? WHERE userID = ?;",
101+
[value, str(user_id)])
102102
self.connection.commit()
103103

104-
def is_user_saved(self, user_id):
104+
def is_user_saved(self, user_id: int) -> bool:
105105
self.cursor.execute("SELECT rowid, * FROM users WHERE userID=?;", [str(user_id)])
106106

107107
result = self.cursor.fetchall()
@@ -110,7 +110,7 @@ def is_user_saved(self, user_id):
110110
else:
111111
return False
112112

113-
def user_data_changed(self, user_id, first_name, last_name, username):
113+
def user_data_changed(self, user_id: int, first_name: str, last_name: str, username: str) -> bool:
114114
self.cursor.execute("SELECT * FROM users WHERE userID=?;", [str(user_id)])
115115

116116
result = self.cursor.fetchone()
@@ -123,15 +123,15 @@ def user_data_changed(self, user_id, first_name, last_name, username):
123123
else:
124124
return True
125125

126-
def update_user_data(self, user_id, first_name, last_name, username):
127-
self.cursor.execute("UPDATE users SET first_name=?, last_name=?, username=? WHERE userID=?;", (str(first_name), str(last_name), str(username), str(user_id)))
126+
def update_user_data(self, user_id: int, first_name: str, last_name: str, username: str) -> None:
127+
self.cursor.execute("UPDATE users SET first_name=?, last_name=?, username=? WHERE userID=?;", (first_name, last_name, username, str(user_id)))
128128
self.connection.commit()
129129

130-
def reset_stats(self, user_id):
130+
def reset_stats(self, user_id: int) -> None:
131131
self.cursor.execute("UPDATE users SET gamesPlayed='0', gamesWon='0', gamesTie='0', lastPlayed='0' WHERE userID=?;", [str(user_id)])
132132
self.connection.commit()
133133

134-
def close_conn(self):
134+
def close_conn(self) -> None:
135135
self.connection.close()
136136

137137
instance = None
@@ -141,7 +141,7 @@ def __init__(self):
141141
DBwrapper.instance = DBwrapper.__DBwrapper()
142142

143143
@staticmethod
144-
def get_instance():
144+
def get_instance() -> __DBwrapper:
145145
if not DBwrapper.instance:
146146
DBwrapper.instance = DBwrapper.__DBwrapper()
147147

database/statistics.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ def set_game_won(user_id):
1919

2020
def add_game_played(user_id):
2121
db = DBwrapper.get_instance()
22-
games_played = int(db.get_played_games(user_id))
22+
games_played = db.get_played_games(user_id)
2323
games_played = games_played + 1
2424
logger.debug("Add game played for userID: " + str(user_id))
2525
db.insert("gamesPlayed", str(games_played), user_id)
26-
db.insert("lastPlayed", int(time()), user_id)
26+
db.insert("lastPlayed", str(int(time())), user_id)
2727

2828

2929
def get_stats(percentage):

game/blackJack.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def dealers_turn(self):
155155
self.send_message(self.chat_id, output_text, parse_mode="Markdown", reply_markup=self.keyboard_running)
156156
self.evaluation()
157157

158-
def start_game(self, message_id=None):
158+
def start_game(self, message_id: int = None) -> None:
159159
if not self.game_running:
160160
if ((self.game_type == self.GROUP_CHAT or self.game_type == self.MULTIPLAYER_GAME) and len(self.players) > 1) or self.game_type == self.PRIVATE_CHAT:
161161
self.game_running = True
@@ -174,7 +174,7 @@ def start_game(self, message_id=None):
174174
# TODO Game already running
175175
pass
176176

177-
def evaluation(self):
177+
def evaluation(self) -> None:
178178
list_21 = []
179179
list_busted = []
180180
list_lower_21 = []
@@ -243,7 +243,7 @@ def evaluation(self):
243243
self.send_message(self.chat_id, final_message, game_id=self.__game_id)
244244
self.game_handler.gl_remove(self.chat_id)
245245

246-
def get_player_overview(self, show_points=False, text="", i=0, dealer=False):
246+
def get_player_overview(self, show_points: bool = False, text: str = "", i=0, dealer: bool = False) -> str:
247247
if self.game_running:
248248
for user in self.players:
249249
if i == self.current_player:
@@ -297,7 +297,7 @@ def analyze_message(self, update):
297297
if user_id == self.players[0].user_id:
298298
self.game_handler.gl_remove(self.chat_id)
299299

300-
def get_game_id(self):
300+
def get_game_id(self) -> int:
301301
return self.__game_id
302302

303303
# When game is being initialized

lang/language.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414

1515
# translate returns the translation for a specific string
16-
def translate(string, language):
16+
def translate(string: str, language: str) -> str:
1717
if language in translations and string in translations[language]:
1818
return translations[language][string]
1919
elif language == "br":

0 commit comments

Comments
 (0)