Fix client.on() type hint (#4415)

This commit is contained in:
xplus2g4 2024-07-24 22:39:25 +08:00 committed by GitHub
parent 65a4a96dbc
commit 2ab4bed02d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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: