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:
Юрий 2020-09-13 22:09:43 +03:00 committed by GitHub
parent 51547f9745
commit 00202565e4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View file

@ -4,6 +4,7 @@ For more comprehensive example see callback_data_factory.py
"""
import logging
import typing
from aiogram import Bot, Dispatcher, executor, types
from aiogram.contrib.middlewares.logging import LoggingMiddleware
@ -38,7 +39,7 @@ async def cmd_start(message: types.Message):
@dp.callback_query_handler(vote_cb.filter(action=['up', 'down']))
async def callback_vote_action(query: types.CallbackQuery, callback_data: dict):
async def callback_vote_action(query: types.CallbackQuery, callback_data: typing.Dict[str, str]):
logging.info('Got this callback data: %r', callback_data) # callback_data contains all info from callback data
await query.answer() # don't forget to answer callback query as soon as possible
callback_data_action = callback_data['action']