-
Notifications
You must be signed in to change notification settings - Fork 522
Make .sleep(..) return a coroutine
#18772
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Make `Clock.sleep(..)` return a coroutine, so that mypy can catch places where we don't await on it. |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -27,7 +27,6 @@ | |||||||||
| Any, | ||||||||||
| Callable, | ||||||||||
| Dict, | ||||||||||
| Generator, | ||||||||||
| Iterator, | ||||||||||
| Mapping, | ||||||||||
| Optional, | ||||||||||
|
|
@@ -42,7 +41,6 @@ | |||||||||
| from typing_extensions import ParamSpec | ||||||||||
|
|
||||||||||
| from twisted.internet import defer, task | ||||||||||
| from twisted.internet.defer import Deferred | ||||||||||
| from twisted.internet.interfaces import IDelayedCall, IReactorTime | ||||||||||
| from twisted.internet.task import LoopingCall | ||||||||||
| from twisted.python.failure import Failure | ||||||||||
|
|
@@ -121,13 +119,11 @@ class Clock: | |||||||||
|
|
||||||||||
| _reactor: IReactorTime = attr.ib() | ||||||||||
|
|
||||||||||
| @defer.inlineCallbacks | ||||||||||
| def sleep(self, seconds: float) -> "Generator[Deferred[float], Any, Any]": | ||||||||||
| async def sleep(self, seconds: float) -> None: | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like this other spot doesn't have types and is in synapse/contrib/cmdclient/http.py Lines 178 to 181 in 7ed5566
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, mmm good spot. Looking at it though I'm disinclined to try and move it to async/await as it still users generators and |
||||||||||
| d: defer.Deferred[float] = defer.Deferred() | ||||||||||
| with context.PreserveLoggingContext(): | ||||||||||
| self._reactor.callLater(seconds, d.callback, seconds) | ||||||||||
| res = yield d | ||||||||||
| return res | ||||||||||
| await d | ||||||||||
|
|
||||||||||
| def time(self) -> float: | ||||||||||
| """Returns the current system time in seconds since epoch.""" | ||||||||||
|
|
||||||||||
Uh oh!
There was an error while loading. Please reload this page.