Scrapy, a fast high-level web crawling & scraping framework for Python.
Silence improper typing of twisted.internet.reactor in tests.
Andrey Rakhmatullin2e33fb812b22
diff --git a/scrapy/utils/benchserver.py b/scrapy/utils/benchserver.pyindex 32bc2e38c..750d3c093 100644--- a/scrapy/utils/benchserver.py+++ b/scrapy/utils/benchserver.py@@ -37,11 +37,11 @@ if __name__ == "__main__":root = Root()factory = Site(root)- httpPort = reactor.listenTCP(8998, Site(root))+ httpPort = reactor.listenTCP(8998, Site(root)) # type: ignore[attr-defined]def _print_listening():httpHost = httpPort.getHost()print(f"Bench server at http://{httpHost.host}:{httpHost.port}")- reactor.callWhenRunning(_print_listening)- reactor.run()+ reactor.callWhenRunning(_print_listening) # type: ignore[attr-defined]+ reactor.run() # type: ignore[attr-defined]diff --git a/tests/CrawlerRunner/ip_address.py b/tests/CrawlerRunner/ip_address.pyindex 26db16dd6..b9a4485a9 100644--- a/tests/CrawlerRunner/ip_address.py+++ b/tests/CrawlerRunner/ip_address.py@@ -41,10 +41,10 @@ if __name__ == "__main__":url = f"http://not.a.real.domain:{port}/echo"servers = [(mock_dns_server.host, mock_dns_server.port)]- reactor.installResolver(createResolver(servers=servers))+ reactor.installResolver(createResolver(servers=servers)) # type: ignore[attr-defined]configure_logging()runner = CrawlerRunner()d = runner.crawl(LocalhostSpider, url=url)- d.addBoth(lambda _: reactor.stop())- reactor.run()+ d.addBoth(lambda _: reactor.stop()) # type: ignore[attr-defined]+ reactor.run() # type: ignore[attr-defined]diff --git a/tests/mockserver.py b/tests/mockserver.pyindex e07ae8797..185897373 100644--- a/tests/mockserver.py+++ b/tests/mockserver.py@@ -10,6 +10,7 @@ from urllib.parse import urlencodefrom OpenSSL import SSLfrom twisted.internet import defer, reactor, ssl+from twisted.internet.protocol import ServerFactoryfrom twisted.internet.task import deferLaterfrom twisted.names import dns, errorfrom twisted.names.server import DNSServerFactory@@ -369,12 +370,14 @@ if __name__ == "__main__":)args = parser.parse_args()+ factory: ServerFactory+if args.type == "http":root = Root()factory = Site(root)- httpPort = reactor.listenTCP(0, factory)+ httpPort = reactor.listenTCP(0, factory) # type: ignore[attr-defined]contextFactory = ssl_context_factory()- httpsPort = reactor.listenSSL(0, factory, contextFactory)+ httpsPort = reactor.listenSSL(0, factory, contextFactory) # type: ignore[attr-defined]def print_listening():httpHost = httpPort.getHost()@@ -388,11 +391,11 @@ if __name__ == "__main__":clients = [MockDNSResolver()]factory = DNSServerFactory(clients=clients)protocol = dns.DNSDatagramProtocol(controller=factory)- listener = reactor.listenUDP(0, protocol)+ listener = reactor.listenUDP(0, protocol) # type: ignore[attr-defined]def print_listening():host = listener.getHost()print(f"{host.host}:{host.port}")- reactor.callWhenRunning(print_listening)- reactor.run()+ reactor.callWhenRunning(print_listening) # type: ignore[attr-defined]+ reactor.run() # type: ignore[attr-defined]diff --git a/tests/test_engine.py b/tests/test_engine.pyindex 7ddb420ba..5fb87424b 100644--- a/tests/test_engine.py+++ b/tests/test_engine.py@@ -557,4 +557,4 @@ class EngineTest(unittest.TestCase):if __name__ == "__main__":if len(sys.argv) > 1 and sys.argv[1] == "runserver":start_test_site(debug=True)- reactor.run()+ reactor.run() # type: ignore[attr-defined]