mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-25 02:43:45 +03:00
Fix async filter call in combinators (#4435)
This commit is contained in:
parent
eb7ed5dd31
commit
ee3248c3a4
|
@ -1,6 +1,7 @@
|
|||
import abc
|
||||
import typing
|
||||
from collections.abc import Callable
|
||||
from inspect import isawaitable
|
||||
from typing import Awaitable, TypeAlias
|
||||
|
||||
from ..event import Event
|
||||
|
@ -41,7 +42,7 @@ class Combinable(abc.ABC):
|
|||
return self.filter if isinstance(self, Not) else Not(self) # type: ignore [return-value]
|
||||
|
||||
@abc.abstractmethod
|
||||
def __call__(self, event: Event) -> bool:
|
||||
async def __call__(self, event: Event) -> bool:
|
||||
pass
|
||||
|
||||
|
||||
|
@ -81,8 +82,12 @@ class Any(Combinable):
|
|||
"""
|
||||
return self._filters
|
||||
|
||||
def __call__(self, event: Event) -> bool:
|
||||
return any(f(event) for f in self._filters)
|
||||
async def __call__(self, event: Event) -> bool:
|
||||
for f in self._filters:
|
||||
if await r if isawaitable(r := f(event)) else r:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
class All(Combinable):
|
||||
|
@ -121,8 +126,12 @@ class All(Combinable):
|
|||
"""
|
||||
return self._filters
|
||||
|
||||
def __call__(self, event: Event) -> bool:
|
||||
return all(f(event) for f in self._filters)
|
||||
async def __call__(self, event: Event) -> bool:
|
||||
for f in self._filters:
|
||||
if not (await r if isawaitable(r := f(event)) else r):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
class Not(Combinable):
|
||||
|
@ -159,5 +168,5 @@ class Not(Combinable):
|
|||
"""
|
||||
return self._filter
|
||||
|
||||
def __call__(self, event: Event) -> bool:
|
||||
return not self._filter(event)
|
||||
async def __call__(self, event: Event) -> bool:
|
||||
return not (await r if isawaitable(r := self._filter(event)) else r)
|
||||
|
|
Loading…
Reference in New Issue
Block a user