static type checking

This commit is contained in:
Forevka 2021-07-03 12:25:03 +00:00 committed by GitHub
parent ed49164328
commit 74574b4b5f

View file

@ -1,19 +1,21 @@
from aiogram.dispatcher.router import Router
from itertools import chain
from typing import List
from typing import List, cast
from aiogram.dispatcher.dispatcher import Dispatcher
AIOGRAM_INTERNAL_HANDLERS = ['update', 'error', ]
def get_handlers_in_use(dispatcher: Dispatcher, handlers_to_skip: List[str] = AIOGRAM_INTERNAL_HANDLERS) -> List[str]:
handlers_in_use = []
handlers_in_use: List[str] = []
for router in [dispatcher.sub_routers, dispatcher]:
if (isinstance(router, list)):
if (router):
handlers_in_use.extend(chain(*list(map(get_handlers_in_use, router))))
else:
router = cast(Router, router)
for update_name, observer in router.observers.items():
if (observer.handlers and update_name not in [*handlers_to_skip, *handlers_in_use]):
handlers_in_use.append(update_name)