[Python] How to check the name of function in outer_middleware after invoking of a handler...

Discussão em 'Python' iniciado por Stack, Março 16, 2025.

  1. Stack

    Stack Membro Participativo

    I have middleware class of telegram bot system:

    from typing import Any, Awaitable, Callable, Dict
    import logging
    import inspect
    from pprint import pprint

    from aiogram import BaseMiddleware
    from aiogram.types import TelegramObject


    logger = logging.getLogger(__name__)

    class LoggingMiddleware(BaseMiddleware):
    async def __call__(
    self, handler: Callable[[TelegramObject, Dict[str, Any]], Awaitable[Any]],
    event: TelegramObject,
    data: Dict[str, Any]
    ) -> Any:
    result = await handler(event, data)
    logger.debug(f"##THIS IS MOCK LOGGER: ")
    return result


    I attach it to dispatcher as an outer_middleware. I want to check which function has been invoked by result = await handler(event, data) and show it's name in logs.

    I have tried to reveal that by inspect module, but i get a lot of non-understandable-by-myself information.

    Continue reading...

Compartilhe esta Página