-
-
Notifications
You must be signed in to change notification settings - Fork 43
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
Allow client.on_session_change to Use Both Coroutine and Regular Functions #466
Comments
I understand that could be confusing at the first look, but you will got clarify right after looks at method/function signature. Just right after hovering on the method in IDE. About Speaking of Combining 2 types of callbacks is a real pain to make it work perfectly with static type checkers (even basic one in IDE). Mixing both interfaces also is not simple task in Python... But this particular case probably could be easily done with one additional "if" statement and blocking call of the handlers. And pray that dev will not put something huge into the handler which will stop the world. tl;dr sync/async is always a choice depending on the performed operations inside and possible usage; not "let's always use async because it is |
I agree with your intention, and I apologize for any confusion caused. My mention of In other words, my suggestion was regarding whether there is a need for the Looking at the implementation, in Since the callback function returns Thank you for your precise type specifications and your excellent efforts in maintaining this module. While I still lack extensive knowledge in typing, I hope to contribute someday. |
The requirement for the callback function
client.on_session_change
to be a coroutine inAsyncClient
causes inconvenience. In many cases, detecting session changes and storing them in an arbitrary repository can be sufficiently fulfilled without being async.When using
AsyncClient
, it is easy to assume that all related methods and functions are coroutines. However, there are exceptions. Theclient.export_session_string()
method is always a blocking function.Expected:
It would be beneficial if the
client.on_session_change
callback function could be inspected internally to allow the use of both coroutine and regular blocking functions.The text was updated successfully, but these errors were encountered: