Scrapy, a fast high-level web crawling & scraping framework for Python.
Typing fixes and updates. (#6460)
Andrey Rakhmatullin5794071f9679
diff --git a/scrapy/pipelines/media.py b/scrapy/pipelines/media.pyindex ea36a9e8a..6bd3ed9b4 100644--- a/scrapy/pipelines/media.py+++ b/scrapy/pipelines/media.py@@ -211,7 +211,7 @@ class MediaPipeline(ABC):# minimize cached information for failureresult.cleanFailure()result.frames = []- result.stack = None+ result.stack = []# This code fixes a memory leak by avoiding to keep references to# the Request and Response objects on the Media Pipeline cache.diff --git a/scrapy/utils/defer.py b/scrapy/utils/defer.pyindex c5763a06c..33ec23cec 100644--- a/scrapy/utils/defer.py+++ b/scrapy/utils/defer.py@@ -19,6 +19,7 @@ from typing import (Callable,Coroutine,Dict,+ Generic,Iterable,Iterator,List,@@ -144,7 +145,7 @@ def parallel(return DeferredList([coop.coiterate(work) for _ in range(count)])-class _AsyncCooperatorAdapter(Iterator[Deferred]):+class _AsyncCooperatorAdapter(Iterator[Deferred], Generic[_T]):"""A class that wraps an async iterable into a normal iterator suitablefor using in Cooperator.coiterate(). As it's only needed for parallel_async(),it calls the callable directly in the callback, instead of providing a morediff --git a/scrapy/utils/log.py b/scrapy/utils/log.pyindex 439b065a9..4a70de6b4 100644--- a/scrapy/utils/log.py+++ b/scrapy/utils/log.py@@ -128,7 +128,7 @@ def configure_logging(settings = Settings(settings)if settings.getbool("LOG_STDOUT"):- sys.stdout = StreamLogger(logging.getLogger("stdout")) # type: ignore[assignment]+ sys.stdout = StreamLogger(logging.getLogger("stdout"))if install_root_handler:install_scrapy_root_handler(settings)diff --git a/scrapy/utils/ssl.py b/scrapy/utils/ssl.pyindex 95611ebd9..2c3a259c1 100644--- a/scrapy/utils/ssl.py+++ b/scrapy/utils/ssl.py@@ -20,7 +20,7 @@ def x509name_to_string(x509name: X509Name) -> str:# from OpenSSL.crypto.X509Name.__repr__result_buffer: Any = pyOpenSSLutil.ffi.new("char[]", 512)pyOpenSSLutil.lib.X509_NAME_oneline(- x509name._name, result_buffer, len(result_buffer) # type: ignore[attr-defined]+ x509name._name, result_buffer, len(result_buffer))return ffi_buf_to_string(result_buffer)diff --git a/tox.ini b/tox.iniindex e3dd96425..2d62f1cb7 100644--- a/tox.ini+++ b/tox.ini@@ -46,16 +46,16 @@ install_command =[testenv:typing]basepython = python3deps =- mypy==1.10.1+ mypy==1.11.1typing-extensions==4.12.2- types-lxml==2024.4.14+ types-lxml==2024.8.7types-Pygments==2.18.0.20240506- types-pyOpenSSL==24.1.0.20240425- types-setuptools==70.3.0.20240710- botocore-stubs==1.34.143- boto3-stubs[s3]==1.34.143+ types-setuptools==71.1.0.20240806+ botocore-stubs==1.34.158+ boto3-stubs[s3]==1.34.158attrs >= 18.2.0Pillow >= 10.3.0+ pyOpenSSL >= 24.2.1pytest >= 8.2.0w3lib >= 2.2.0commands =