From 3b5b6a1da73e00ec527d170772b2bb329d82373a Mon Sep 17 00:00:00 2001 From: Jahongir Qurbonov Date: Tue, 20 Aug 2024 00:30:46 +0500 Subject: [PATCH] Fix typo --- .../telethon/_impl/client/client/client.py | 12 +++++----- .../telethon/_impl/client/client/updates.py | 10 ++++---- .../_impl/client/events/filters/__init__.py | 4 ++-- .../client/events/filters/combinators.py | 24 +++++++++++-------- .../_impl/client/types/buttons/button.py | 6 ++--- client/src/telethon/events/filters.py | 5 ++-- 6 files changed, 33 insertions(+), 28 deletions(-) diff --git a/client/src/telethon/_impl/client/client/client.py b/client/src/telethon/_impl/client/client/client.py index 24b40e81..bad3adb6 100644 --- a/client/src/telethon/_impl/client/client/client.py +++ b/client/src/telethon/_impl/client/client/client.py @@ -23,7 +23,7 @@ from ...session import ( ) from ...tl import Request, abcs from ..events import Event -from ..events.filters import Filter +from ..events.filters import FilterType from ..types import ( AdminRight, AlbumBuilder, @@ -258,7 +258,7 @@ class Client: self._dispatcher: Optional[asyncio.Task[None]] = None self._handlers: dict[ Type[Event], - list[tuple[Callable[[Any], Awaitable[Any]], Optional[Filter]]], + list[tuple[Callable[[Any], Awaitable[Any]], Optional[FilterType]]], ] = {} self._check_all_handlers = check_all_handlers @@ -272,7 +272,7 @@ class Client: handler: Callable[[AnyEvent], Awaitable[Any]], /, event_cls: Type[AnyEvent], - filter: Optional[Filter] = None, + filter: Optional[FilterType] = None, ) -> None: """ Register a callable to be invoked when the provided event type occurs. @@ -761,7 +761,7 @@ class Client: def get_handler_filter( self, handler: Callable[[AnyEvent], Awaitable[Any]], / - ) -> Optional[Filter]: + ) -> Optional[FilterType]: """ Get the filter associated to the given event handler. @@ -1036,7 +1036,7 @@ class Client: return await is_authorized(self) def on( - self, event_cls: Type[AnyEvent], /, filter: Optional[Filter] = None + self, event_cls: Type[AnyEvent], /, filter: Optional[FilterType] = None ) -> Callable[ [Callable[[AnyEvent], Awaitable[Any]]], Callable[[AnyEvent], Awaitable[Any]] ]: @@ -1853,7 +1853,7 @@ class Client: self, handler: Callable[[AnyEvent], Awaitable[Any]], /, - filter: Optional[Filter] = None, + filter: Optional[FilterType] = None, ) -> None: """ Set the filter to use for the given event handler. diff --git a/client/src/telethon/_impl/client/client/updates.py b/client/src/telethon/_impl/client/client/updates.py index 00096378..388785f9 100644 --- a/client/src/telethon/_impl/client/client/updates.py +++ b/client/src/telethon/_impl/client/client/updates.py @@ -9,7 +9,7 @@ from ...session import Gap from ...tl import abcs from ..events import Continue from ..events import Event as EventBase -from ..events.filters import Filter +from ..events.filters import FilterType from ..types import build_chat_map if TYPE_CHECKING: @@ -21,7 +21,7 @@ UPDATE_LIMIT_EXCEEDED_LOG_COOLDOWN = 300 def on( - self: Client, event_cls: Type[Event], /, filter: Optional[Filter] = None + self: Client, event_cls: Type[Event], /, filter: Optional[FilterType] = None ) -> Callable[[Callable[[Event], Awaitable[Any]]], Callable[[Event], Awaitable[Any]]]: def wrapper( handler: Callable[[Event], Awaitable[Any]], @@ -37,7 +37,7 @@ def add_event_handler( handler: Callable[[Event], Awaitable[Any]], /, event_cls: Type[Event], - filter: Optional[Filter] = None, + filter: Optional[FilterType] = None, ) -> None: self._handlers.setdefault(event_cls, []).append((handler, filter)) @@ -55,7 +55,7 @@ def remove_event_handler( def get_handler_filter( self: Client, handler: Callable[[Event], Awaitable[Any]], / -) -> Optional[Filter]: +) -> Optional[FilterType]: for handlers in self._handlers.values(): for h, f in handlers: if h == handler: @@ -67,7 +67,7 @@ def set_handler_filter( self: Client, handler: Callable[[Event], Awaitable[Any]], /, - filter: Optional[Filter] = None, + filter: Optional[FilterType] = None, ) -> None: for handlers in self._handlers.values(): for i, (h, _) in enumerate(handlers): diff --git a/client/src/telethon/_impl/client/events/filters/__init__.py b/client/src/telethon/_impl/client/events/filters/__init__.py index cca00c36..f6f3a7ae 100644 --- a/client/src/telethon/_impl/client/events/filters/__init__.py +++ b/client/src/telethon/_impl/client/events/filters/__init__.py @@ -1,12 +1,12 @@ from .callback import Data -from .combinators import All, Any, Filter, Not +from .combinators import All, Any, FilterType, Not from .common import Chats, ChatType, Senders from .messages import Command, Forward, Incoming, Media, Outgoing, Reply, Text __all__ = [ "All", "Any", - "Filter", + "FilterType", "Not", "Chats", "ChatType", diff --git a/client/src/telethon/_impl/client/events/filters/combinators.py b/client/src/telethon/_impl/client/events/filters/combinators.py index 7835526d..ff03dfeb 100644 --- a/client/src/telethon/_impl/client/events/filters/combinators.py +++ b/client/src/telethon/_impl/client/events/filters/combinators.py @@ -6,7 +6,7 @@ from typing import Awaitable, TypeAlias from ..event import Event -Filter: TypeAlias = Callable[[Event], bool | Awaitable[bool]] +FilterType: TypeAlias = Callable[[Event], bool | Awaitable[bool]] class Combinable(abc.ABC): @@ -22,7 +22,7 @@ class Combinable(abc.ABC): Multiple ``~`` will toggle between using :class:`Not` and not using it. """ - def __or__(self, other: typing.Any) -> Filter: + def __or__(self, other: typing.Any) -> FilterType: if not callable(other): return NotImplemented @@ -30,7 +30,7 @@ class Combinable(abc.ABC): rhs = other.filters if isinstance(other, Any) else (other,) return Any(*lhs, *rhs) # type: ignore [arg-type] - def __and__(self, other: typing.Any) -> Filter: + def __and__(self, other: typing.Any) -> FilterType: if not callable(other): return NotImplemented @@ -38,7 +38,7 @@ class Combinable(abc.ABC): rhs = other.filters if isinstance(other, All) else (other,) return All(*lhs, *rhs) # type: ignore [arg-type] - def __invert__(self) -> Filter: + def __invert__(self) -> FilterType: return self.filter if isinstance(self, Not) else Not(self) # type: ignore [return-value] @abc.abstractmethod @@ -72,11 +72,13 @@ class Any(Combinable): __slots__ = ("_filters",) - def __init__(self, filter1: Filter, filter2: Filter, *filters: Filter) -> None: + def __init__( + self, filter1: FilterType, filter2: FilterType, *filters: FilterType + ) -> None: self._filters = (filter1, filter2, *filters) @property - def filters(self) -> tuple[Filter, ...]: + def filters(self) -> tuple[FilterType, ...]: """ The filters being checked, in order. """ @@ -116,11 +118,13 @@ class All(Combinable): __slots__ = ("_filters",) - def __init__(self, filter1: Filter, filter2: Filter, *filters: Filter) -> None: + def __init__( + self, filter1: FilterType, filter2: FilterType, *filters: FilterType + ) -> None: self._filters = (filter1, filter2, *filters) @property - def filters(self) -> tuple[Filter, ...]: + def filters(self) -> tuple[FilterType, ...]: """ The filters being checked, in order. """ @@ -158,11 +162,11 @@ class Not(Combinable): __slots__ = ("_filter",) - def __init__(self, filter: Filter) -> None: + def __init__(self, filter: FilterType) -> None: self._filter = filter @property - def filter(self) -> Filter: + def filter(self) -> FilterType: """ The filter being negated. """ diff --git a/client/src/telethon/_impl/client/types/buttons/button.py b/client/src/telethon/_impl/client/types/buttons/button.py index 558e8ef6..6932380d 100644 --- a/client/src/telethon/_impl/client/types/buttons/button.py +++ b/client/src/telethon/_impl/client/types/buttons/button.py @@ -1,7 +1,7 @@ from __future__ import annotations import weakref -from typing import TYPE_CHECKING, Optional +from typing import TYPE_CHECKING, Optional, TypeAlias from ....tl import types @@ -9,7 +9,7 @@ if TYPE_CHECKING: from ..message import Message -ButtonTypes = ( +ButtonType: TypeAlias = ( types.KeyboardButton | types.KeyboardButtonUrl | types.KeyboardButtonCallback @@ -53,7 +53,7 @@ class Button: f"Can't instantiate abstract class {self.__class__.__name__}" ) - self._raw: ButtonTypes = types.KeyboardButton(text=text) + self._raw: ButtonType = types.KeyboardButton(text=text) self._msg: Optional[weakref.ReferenceType[Message]] = None @property diff --git a/client/src/telethon/events/filters.py b/client/src/telethon/events/filters.py index 2ef8ad38..d76a90a7 100644 --- a/client/src/telethon/events/filters.py +++ b/client/src/telethon/events/filters.py @@ -7,6 +7,7 @@ When the return value is :data:`True`, the associated :mod:`~telethon.events` ha The :doc:`/concepts/updates` concept to learn to combine filters or define your own. """ + from .._impl.client.events.filters import ( All, Any, @@ -14,7 +15,7 @@ from .._impl.client.events.filters import ( ChatType, Command, Data, - Filter, + FilterType, Forward, Incoming, Media, @@ -31,7 +32,7 @@ __all__ = [ "Chats", "ChatType", "Command", - "Filter", + "FilterType", "Forward", "Incoming", "Media",