From 764a9d47bb95e87519a4fc2fe20ddf0c97b11739 Mon Sep 17 00:00:00 2001 From: Andrey Rakhmatullin Date: Wed, 25 Jan 2023 22:31:12 +0400 Subject: [PATCH] Fix typing of inlineCallbacks-decorated functions. --- scrapy/core/engine.py | 6 +++--- scrapy/core/spidermw.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scrapy/core/engine.py b/scrapy/core/engine.py index 19696415b..cafa7f6da 100644 --- a/scrapy/core/engine.py +++ b/scrapy/core/engine.py @@ -7,7 +7,7 @@ For more information see docs/topics/architecture.rst import logging import warnings from time import time -from typing import Callable, Iterable, Iterator, Optional, Set, Union +from typing import Any, Callable, Generator, Iterable, Iterator, Optional, Set, Union from twisted.internet.defer import Deferred, inlineCallbacks, succeed from twisted.internet.task import LoopingCall @@ -96,7 +96,7 @@ class ExecutionEngine: return scheduler_cls @inlineCallbacks - def start(self) -> Deferred: + def start(self) -> Generator[Deferred, Any, None]: if self.running: raise RuntimeError("Engine already running") self.start_time = time() @@ -109,7 +109,7 @@ class ExecutionEngine: """Gracefully stop the execution engine""" @inlineCallbacks - def _finish_stopping_engine(_) -> Deferred: + def _finish_stopping_engine(_) -> Generator[Deferred, Any, None]: yield self.signals.send_catch_log_deferred(signal=signals.engine_stopped) self._closewait.callback(None) diff --git a/scrapy/core/spidermw.py b/scrapy/core/spidermw.py index 1aaed5865..0bc8d54d2 100644 --- a/scrapy/core/spidermw.py +++ b/scrapy/core/spidermw.py @@ -182,7 +182,7 @@ class SpiderMiddlewareManager(MiddlewareManager): spider: Spider, result: Union[Iterable, AsyncIterable], start_index: int = 0, - ) -> Deferred: + ) -> Generator[Deferred, Any, Union[MutableChain, MutableAsyncChain]]: # items in this iterable do not need to go through the process_spider_output # chain, they went through it already from the process_spider_exception method recovered: Union[MutableChain, MutableAsyncChain]