-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Consider to convert inlineCallbacks to async/await #7371
Comments
Buildbot will transition to async/await at some point. One problem is that moving from inlineCallbacks to async/await changes return type of a function from defer.Deferred to coroutine. Users may be relying on additional functionality exposed by defer.Deferred() class. Thus the migration will be rather complex. |
This would help a lot with type hints as from typing import Any
from typing import Generator
from typing import TypeVar
T = TypeVar('T')
InlineCallBackType = Generator[defer.Deferred[Any], Any, T]
...
@defer.inlineCallbacks
def _function() -> InlineCallbackType[int]:
yield ...
...
return 1 but it's a bit annoying when a subclass override a method with an implementation that does not need yielding. @defer.inlineCallbacks
def _function() -> InlineCallbackType[int]:
yield defer.succeed(None)
return 1 Looking a bit at the matrix code pre-async transition, it looks like they didn't bother with typing the returns of their
Looks like that can be handled pretty easily by user code with
That could allow a more aggressive transition to take place in the next minor version. |
Twisted documentation for Inline callbacks - using ‘yield’ states
As Buildbot dropped support for Python2 there is opportunity to convert inlineCallbacks to async/await.
I’m not sure if it helps.
Some thoughts on why and how to do this are given in matrix-org/synapse#7988 (comment)
This is related blogpost https://patrick.cloke.us/posts/2021/06/11/converting-twisteds-inlinecallbacks-to-async/
The text was updated successfully, but these errors were encountered: