Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for both sync and async filters #437

Merged
merged 4 commits into from Aug 21, 2020

Conversation

@HasibulKabir
Copy link
Contributor

@HasibulKabir HasibulKabir commented Jul 7, 2020

No description provided.

@@ -188,8 +188,12 @@ async def update_worker(self, lock):

if isinstance(handler, handler_type):
try:
if handler.check(parsed_update):
args = (parsed_update,)
if callable(handler.filters) and asyncio.iscoroutinefunction(handler.filters.__call__):

This comment has been minimized.

@delivrance

delivrance Jul 8, 2020
Member

callable(handler.filters) is not actually needed. Filter objects in the current API always have __call__ defined, if they don't they are not proper filters and pyrogram will raise an exception when accessing handler.filters.__call__, which is better than having it silently ignore updates.

This comment has been minimized.

@delivrance

delivrance Jul 8, 2020
Member

I think we should remove all of these checks here and have handler.check actually check for coroutine functions. It also helps removing one repeated line args = (parsed_update,).

This comment has been minimized.

@HasibulKabir

HasibulKabir Jul 8, 2020
Author Contributor

sure.

delivrance and others added 2 commits Jul 8, 2020
@@ -46,5 +46,5 @@ class DeletedMessagesHandler(Handler):
def __init__(self, callback: callable, filters=None):
super().__init__(callback, filters)

def check(self, messages):
return super().check(messages[0])
async def check(self, messages):

This comment has been minimized.

@delivrance

delivrance Jul 8, 2020
Member

You checked for other usages. Good!

return (self.filters(update))

else:
return (True)

This comment has been minimized.

@delivrance

delivrance Jul 8, 2020
Member

Why all these parentheses?

This comment has been minimized.

@HasibulKabir

HasibulKabir Jul 9, 2020
Author Contributor

I have checked after this commit. I have removed last line and added parentheses in return.

@delivrance delivrance merged commit ecab62c into pyrogram:asyncio-dev Aug 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.