From 8345ecd4d105a615079de5a918f0e47b1c73dd76 Mon Sep 17 00:00:00 2001 From: Loren Arthur Date: Thu, 1 Aug 2019 23:09:11 -0700 Subject: [PATCH] Update type annotations. --- tornado/gen.py | 13 ++++++------- tornado/ioloop.py | 8 +++++--- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/tornado/gen.py b/tornado/gen.py index 8ca7ba045c..aa32a2fcd4 100644 --- a/tornado/gen.py +++ b/tornado/gen.py @@ -699,13 +699,13 @@ async def run(self) -> None: future = self.future if future is None: raise Exception("No pending future") - if not self.future.done(): + if not self.future.done(): # type: ignore _step = asyncio.Event() - def step(*args): + def step(f: "Future[_T]") -> None: _step.set() - self.io_loop.add_future(self.future, step) + self.io_loop.add_future(self.future, step) # type: ignore await _step.wait() self.future = None try: @@ -747,18 +747,17 @@ def step(*args): if self.future is moment: await sleep(0) - def handle_yield(self, yielded: _Yieldable) -> bool: + def handle_yield(self, yielded: _Yieldable) -> None: try: self.future = convert_yielded(yielded) except BadYieldError: self.future = Future() future_set_exc_info(self.future, sys.exc_info()) - def finish(self, future): + def finish(self, future: "Future[_T]") -> None: if future.cancelled(): self.task.cancel() - self.future.cancel() - self.task = None + self.future.cancel() # type: ignore # Convert Awaitables into Futures. diff --git a/tornado/ioloop.py b/tornado/ioloop.py index 216bbff23d..6cb2367ab2 100644 --- a/tornado/ioloop.py +++ b/tornado/ioloop.py @@ -506,9 +506,11 @@ def run() -> None: future_cell[0] = fut fut.set_result(result) assert future_cell[0] is not None - self.add_future( - future_cell[0], lambda f: f.add_done_callback(lambda _: self.stop()) - ) + + def _stop(f: "Future[_T]") -> None: + f.add_done_callback(lambda _: self.stop()) + + self.add_future(future_cell[0], _stop) self.add_callback(run) if timeout is not None: