From 2ab4bed02daf01c1570229d069c782a8ffe5fb5b Mon Sep 17 00:00:00 2001 From: xplus2g4 <42161319+xplus2g4@users.noreply.github.com> Date: Wed, 24 Jul 2024 22:39:25 +0800 Subject: [PATCH] Fix client.on() type hint (#4415) --- client/src/telethon/_impl/client/client/client.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/client/src/telethon/_impl/client/client/client.py b/client/src/telethon/_impl/client/client/client.py index 1f32b20b..7896bff2 100644 --- a/client/src/telethon/_impl/client/client/client.py +++ b/client/src/telethon/_impl/client/client/client.py @@ -111,6 +111,7 @@ from .users import get_contacts, get_me, resolve_peers, resolve_phone, resolve_u Return = TypeVar("Return") T = TypeVar("T") +AnyEvent = TypeVar("AnyEvent", bound=Event) class Client: @@ -266,9 +267,9 @@ class Client: def add_event_handler( self, - handler: Callable[[Event], Awaitable[Any]], + handler: Callable[[AnyEvent], Awaitable[Any]], /, - event_cls: Type[Event], + event_cls: Type[AnyEvent], filter: Optional[Filter] = None, ) -> None: """ @@ -757,7 +758,7 @@ class Client: return get_file_bytes(self, media) def get_handler_filter( - self, handler: Callable[[Event], Awaitable[Any]], / + self, handler: Callable[[AnyEvent], Awaitable[Any]], / ) -> Optional[Filter]: """ Get the filter associated to the given event handler. @@ -1033,9 +1034,9 @@ class Client: return await is_authorized(self) def on( - self, event_cls: Type[Event], /, filter: Optional[Filter] = None + self, event_cls: Type[AnyEvent], /, filter: Optional[Filter] = None ) -> Callable[ - [Callable[[Event], Awaitable[Any]]], Callable[[Event], Awaitable[Any]] + [Callable[[AnyEvent], Awaitable[Any]]], Callable[[AnyEvent], Awaitable[Any]] ]: """ Register the decorated function to be invoked when the provided event type occurs. @@ -1158,7 +1159,7 @@ class Client: await read_message(self, chat, message_id) def remove_event_handler( - self, handler: Callable[[Event], Awaitable[Any]], / + self, handler: Callable[[AnyEvent], Awaitable[Any]], / ) -> None: """ Remove the handler as a function to be called when events occur. @@ -1848,7 +1849,7 @@ class Client: def set_handler_filter( self, - handler: Callable[[Event], Awaitable[Any]], + handler: Callable[[AnyEvent], Awaitable[Any]], /, filter: Optional[Filter] = None, ) -> None: