diff --git a/scrapy_zyte_api/_middlewares.py b/scrapy_zyte_api/_middlewares.py index a27031af..629aed4f 100644 --- a/scrapy_zyte_api/_middlewares.py +++ b/scrapy_zyte_api/_middlewares.py @@ -1,4 +1,5 @@ import logging +from typing import cast from scrapy import signals from scrapy.exceptions import IgnoreRequest @@ -83,7 +84,9 @@ def open_spider(self, spider): "either to True or to a dictionary of extra request fields." ) from twisted.internet import reactor + from twisted.internet.interfaces import IReactorCore + reactor = cast(IReactorCore, reactor) reactor.callLater( 0, self._crawler.engine.close_spider, spider, "plugin_conflict" ) diff --git a/tests/test_middlewares.py b/tests/test_middlewares.py index 916977fb..2305d22a 100644 --- a/tests/test_middlewares.py +++ b/tests/test_middlewares.py @@ -1,3 +1,4 @@ +from typing import Any, Dict, cast from unittest import SkipTest from packaging.version import Version @@ -298,7 +299,7 @@ class SPMSpider(Spider): "ZYTE_SMARTPROXY_APIKEY": "foo", **SETTINGS, } - mws = dict(settings["DOWNLOADER_MIDDLEWARES"]) + mws = dict(cast(Dict[Any, int], settings["DOWNLOADER_MIDDLEWARES"])) mws["scrapy_zyte_smartproxy.ZyteSmartProxyMiddleware"] = 610 settings["DOWNLOADER_MIDDLEWARES"] = mws @@ -348,7 +349,7 @@ class CrawleraSpider(Spider): "CRAWLERA_APIKEY": "foo", **SETTINGS, } - mws = dict(settings["DOWNLOADER_MIDDLEWARES"]) + mws = dict(cast(Dict[Any, int], settings["DOWNLOADER_MIDDLEWARES"])) mws["scrapy_crawlera.CrawleraMiddleware"] = 610 settings["DOWNLOADER_MIDDLEWARES"] = mws