Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

Fix typing of inlineCallbacks-decorated functions.

Andrey Rakhmatullin764a9d47bb95
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]