mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-22 09:26:37 +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 abc
|
||||||
import typing
|
import typing
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
|
from inspect import isawaitable
|
||||||
from typing import Awaitable, TypeAlias
|
from typing import Awaitable, TypeAlias
|
||||||
|
|
||||||
from ..event import Event
|
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]
|
return self.filter if isinstance(self, Not) else Not(self) # type: ignore [return-value]
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def __call__(self, event: Event) -> bool:
|
async def __call__(self, event: Event) -> bool:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@ -81,8 +82,12 @@ class Any(Combinable):
|
||||||
"""
|
"""
|
||||||
return self._filters
|
return self._filters
|
||||||
|
|
||||||
def __call__(self, event: Event) -> bool:
|
async def __call__(self, event: Event) -> bool:
|
||||||
return any(f(event) for f in self._filters)
|
for f in self._filters:
|
||||||
|
if await r if isawaitable(r := f(event)) else r:
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
class All(Combinable):
|
class All(Combinable):
|
||||||
|
@ -121,8 +126,12 @@ class All(Combinable):
|
||||||
"""
|
"""
|
||||||
return self._filters
|
return self._filters
|
||||||
|
|
||||||
def __call__(self, event: Event) -> bool:
|
async def __call__(self, event: Event) -> bool:
|
||||||
return all(f(event) for f in self._filters)
|
for f in self._filters:
|
||||||
|
if not (await r if isawaitable(r := f(event)) else r):
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
class Not(Combinable):
|
class Not(Combinable):
|
||||||
|
@ -159,5 +168,5 @@ class Not(Combinable):
|
||||||
"""
|
"""
|
||||||
return self._filter
|
return self._filter
|
||||||
|
|
||||||
def __call__(self, event: Event) -> bool:
|
async def __call__(self, event: Event) -> bool:
|
||||||
return not self._filter(event)
|
return not (await r if isawaitable(r := self._filter(event)) else r)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user