mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
fixed type hints of callback_data (#400)
its impotant to remeber all data saved in callback_data is text even if you pass to it integer insofar as newbies often copy examples and modyfy this typing may help them make no mistake
This commit is contained in:
parent
51547f9745
commit
00202565e4
2 changed files with 6 additions and 4 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import logging
|
||||
import random
|
||||
import uuid
|
||||
import typing
|
||||
|
||||
from aiogram import Bot, Dispatcher, executor, md, types
|
||||
from aiogram.contrib.fsm_storage.memory import MemoryStorage
|
||||
|
|
@ -52,7 +53,7 @@ def format_post(post_id: str, post: dict) -> (str, types.InlineKeyboardMarkup):
|
|||
md.quote_html(post['body']),
|
||||
'', # just new empty line
|
||||
f"Votes: {post['votes']}",
|
||||
sep = '\n',
|
||||
sep='\n',
|
||||
)
|
||||
|
||||
markup = types.InlineKeyboardMarkup()
|
||||
|
|
@ -75,7 +76,7 @@ async def query_show_list(query: types.CallbackQuery):
|
|||
|
||||
|
||||
@dp.callback_query_handler(posts_cb.filter(action='view'))
|
||||
async def query_view(query: types.CallbackQuery, callback_data: dict):
|
||||
async def query_view(query: types.CallbackQuery, callback_data: typing.Dict[str, str]):
|
||||
post_id = callback_data['id']
|
||||
|
||||
post = POSTS.get(post_id, None)
|
||||
|
|
@ -87,7 +88,7 @@ async def query_view(query: types.CallbackQuery, callback_data: dict):
|
|||
|
||||
|
||||
@dp.callback_query_handler(posts_cb.filter(action=['like', 'dislike']))
|
||||
async def query_post_vote(query: types.CallbackQuery, callback_data: dict):
|
||||
async def query_post_vote(query: types.CallbackQuery, callback_data: typing.Dict[str, str]):
|
||||
try:
|
||||
await dp.throttle('vote', rate=1)
|
||||
except Throttled:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue