Skip to content

Commit 2324435

Browse files
committed
Improvements to imports and type hints
1 parent d3e020e commit 2324435

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

bot/handlers/callbacks.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
from bot.keyboards import make_regenerate_keyboard, make_settings_keyboard
99
from bot.localization import get_settings_string
1010
from bot.common import cb_wordcount, cb_separators, cb_prefixes
11+
from bot.config_reader import Config
12+
from bot.pwdgen import XKCD
1113

1214

1315
async def regenerate_custom_password(call: types.CallbackQuery, state: FSMContext):
@@ -17,7 +19,7 @@ async def regenerate_custom_password(call: types.CallbackQuery, state: FSMContex
1719
:param call: Callback Query
1820
:param state: current user's state & data
1921
"""
20-
pwd = call.bot.get("pwd")
22+
pwd: XKCD = call.bot.get("pwd")
2123
data = await state.get_data()
2224
new_password = pwd.custom(data.get("words_count"), data.get("separators"), data.get("prefixes_suffixes"))
2325
await call.message.edit_text(
@@ -33,7 +35,7 @@ async def update_settings_message(call: types.CallbackQuery, data: dict):
3335
:param call: Callback Query
3436
:param data: current user's state & data
3537
"""
36-
config = call.bot.get("config")
38+
config: Config = call.bot.get("config")
3739
lang_code = call.from_user.language_code
3840
words_count = data.get("words_count")
3941
separators_enabled = data.get("separators")
@@ -68,7 +70,6 @@ async def change_words_count(call: types.CallbackQuery, callback_data: dict, sta
6870
:param callback_data: buttons data
6971
:param state: current user's state & data
7072
"""
71-
from bot.config_reader import Config
7273
config: Config = call.bot.get("config")
7374
data = await state.get_data()
7475
old_value = data.get("words_count", 3)

bot/handlers/commands.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44

55
from bot.localization import get_string, get_settings_string
66
from bot.keyboards import make_settings_keyboard, make_regenerate_keyboard
7+
from bot.config_reader import Config
8+
from bot.pwdgen import XKCD
79

810

911
async def cmd_start(message: types.Message, state: FSMContext):
1012
data = await state.get_data()
11-
config = message.bot.get("config")
13+
config: Config = message.bot.get("config")
1214

1315
# Check whether user's settings exist and initialize if missing
1416
if data.get("words_count") is None:
@@ -26,22 +28,22 @@ async def cmd_help(message: types.Message):
2628

2729

2830
async def cmd_generate_weak(message: types.Message):
29-
pwd = message.bot.get("pwd")
31+
pwd: XKCD = message.bot.get("pwd")
3032
await message.answer(hcode(pwd.weak()))
3133

3234

3335
async def cmd_generate_normal(message: types.Message):
34-
pwd = message.bot.get("pwd")
36+
pwd: XKCD = message.bot.get("pwd")
3537
await message.answer(hcode(pwd.normal()))
3638

3739

3840
async def cmd_generate_strong(message: types.Message):
39-
pwd = message.bot.get("pwd")
41+
pwd: XKCD = message.bot.get("pwd")
4042
await message.answer(hcode(pwd.strong()))
4143

4244

4345
async def cmd_generate_custom(message: types.Message, state: FSMContext):
44-
pwd = message.bot.get("pwd")
46+
pwd: XKCD = message.bot.get("pwd")
4547
data = await state.get_data()
4648
custom_pwd = pwd.custom(data.get("words_count"), data.get("separators"), data.get("prefixes_suffixes"))
4749
await message.answer(
@@ -52,13 +54,13 @@ async def cmd_generate_custom(message: types.Message, state: FSMContext):
5254

5355
async def default(message: types.Message):
5456
# same as cmd_generate_normal()
55-
pwd = message.bot.get("pwd")
57+
pwd: XKCD = message.bot.get("pwd")
5658
await message.answer(hcode(pwd.normal()))
5759

5860

5961
async def cmd_settings(message: types.Message, state: FSMContext):
6062
data = await state.get_data()
61-
config = message.bot.get("config")
63+
config: Config = message.bot.get("config")
6264
lang_code = message.from_user.language_code
6365
kb = make_settings_keyboard(
6466
config=config,

bot/handlers/inline_mode.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from aiogram import types, Dispatcher
22
from aiogram.utils.markdown import hcode
33
from bot.localization import get_string
4+
from bot.pwdgen import XKCD
45

56

67
async def inline_handler(query: types.InlineQuery):
7-
pwd = query.bot.get("pwd")
8+
pwd: XKCD = query.bot.get("pwd")
89
data = [
910
{
1011
"title_tag": "inline_strong_title",

0 commit comments

Comments
 (0)