Address PR feedback.

This commit is contained in:
Andrey Rakhmatullin 2024-11-14 19:35:56 +05:00
parent 2ad5f0c12b
commit 929d665a74
4 changed files with 11 additions and 19 deletions

View File

@ -54,14 +54,6 @@ class MiddlewareManager:
@staticmethod
def _build_from_settings(objcls: type[_T], settings: BaseSettings) -> _T:
if hasattr(objcls, "from_settings"):
warnings.warn(
f"{objcls.__qualname__} has from_settings() but not from_crawler()."
" This is deprecated and calling from_settings() will be removed in a future"
" Scrapy version. You can implement a simple from_crawler() that calls"
" from_settings() with crawler.settings.",
category=ScrapyDeprecationWarning,
stacklevel=2,
)
instance = objcls.from_settings(settings) # type: ignore[attr-defined]
method_name = "from_settings"
else:

View File

@ -35,7 +35,7 @@ from scrapy.utils.datatypes import CaseInsensitiveDict
from scrapy.utils.deprecate import method_is_overridden
from scrapy.utils.ftp import ftp_store_file
from scrapy.utils.log import failure_to_exc_info
from scrapy.utils.python import get_func_args, to_bytes
from scrapy.utils.python import get_func_args, global_object_name, to_bytes
from scrapy.utils.request import referer_str
if TYPE_CHECKING:
@ -457,7 +457,7 @@ class FilesPipeline(MediaPipeline):
if settings is not None:
warnings.warn(
f"FilesPipeline.__init__() was called with a crawler instance and a settings instance"
f" when creating {self.__class__.__qualname__}. The settings instance will be ignored"
f" when creating {global_object_name(self.__class__)}. The settings instance will be ignored"
f" and crawler.settings will be used. The settings argument will be removed in a future Scrapy version.",
category=ScrapyDeprecationWarning,
stacklevel=2,
@ -501,7 +501,7 @@ class FilesPipeline(MediaPipeline):
def from_crawler(cls, crawler: Crawler) -> Self:
if method_is_overridden(cls, FilesPipeline, "from_settings"):
warnings.warn(
f"{cls.__name__} overrides FilesPipeline.from_settings()."
f"{global_object_name(cls)} overrides FilesPipeline.from_settings()."
f" This method is deprecated and won't be called in future Scrapy versions,"
f" please update your code so that it overrides from_crawler() instead.",
category=ScrapyDeprecationWarning,
@ -522,7 +522,7 @@ class FilesPipeline(MediaPipeline):
if crawler:
o._finish_init(crawler)
warnings.warn(
f"{cls.__qualname__}.__init__() doesn't take a crawler argument."
f"{global_object_name(cls)}.__init__() doesn't take a crawler argument."
" This is deprecated and the argument will be required in future Scrapy versions.",
category=ScrapyDeprecationWarning,
)

View File

@ -20,7 +20,7 @@ from scrapy.http import Request, Response
from scrapy.http.request import NO_CALLBACK
from scrapy.pipelines.files import FileException, FilesPipeline, _md5sum
from scrapy.settings import Settings
from scrapy.utils.python import get_func_args, to_bytes
from scrapy.utils.python import get_func_args, global_object_name, to_bytes
if TYPE_CHECKING:
from collections.abc import Callable, Iterable
@ -82,7 +82,7 @@ class ImagesPipeline(FilesPipeline):
if settings is not None:
warnings.warn(
f"ImagesPipeline.__init__() was called with a crawler instance and a settings instance"
f" when creating {self.__class__.__qualname__}. The settings instance will be ignored"
f" when creating {global_object_name(self.__class__)}. The settings instance will be ignored"
f" and crawler.settings will be used. The settings argument will be removed in a future Scrapy version.",
category=ScrapyDeprecationWarning,
stacklevel=2,
@ -130,7 +130,7 @@ class ImagesPipeline(FilesPipeline):
if crawler:
o._finish_init(crawler)
warnings.warn(
f"{cls.__qualname__}.__init__() doesn't take a crawler argument."
f"{global_object_name(cls)}.__init__() doesn't take a crawler argument."
" This is deprecated and the argument will be required in future Scrapy versions.",
category=ScrapyDeprecationWarning,
)

View File

@ -28,7 +28,7 @@ from scrapy.utils.datatypes import SequenceExclude
from scrapy.utils.defer import defer_result, mustbe_deferred
from scrapy.utils.log import failure_to_exc_info
from scrapy.utils.misc import arg_to_iter
from scrapy.utils.python import get_func_args
from scrapy.utils.python import get_func_args, global_object_name
if TYPE_CHECKING:
from collections.abc import Callable
@ -85,7 +85,7 @@ class MediaPipeline(ABC):
if settings is not None:
warnings.warn(
f"MediaPipeline.__init__() was called with a crawler instance and a settings instance"
f" when creating {self.__class__.__qualname__}. The settings instance will be ignored"
f" when creating {global_object_name(self.__class__)}. The settings instance will be ignored"
f" and crawler.settings will be used. The settings argument will be removed in a future Scrapy version.",
category=ScrapyDeprecationWarning,
stacklevel=2,
@ -107,7 +107,7 @@ class MediaPipeline(ABC):
else:
warnings.warn(
f"MediaPipeline.__init__() was called without the crawler argument"
f" when creating {self.__class__.__qualname__}."
f" when creating {global_object_name(self.__class__)}."
f" This is deprecated and the argument will be required in future Scrapy versions.",
category=ScrapyDeprecationWarning,
stacklevel=2,
@ -154,7 +154,7 @@ class MediaPipeline(ABC):
else:
pipe = cls()
warnings.warn(
f"{cls.__qualname__}.__init__() doesn't take a crawler argument."
f"{global_object_name(cls)}.__init__() doesn't take a crawler argument."
" This is deprecated and the argument will be required in future Scrapy versions.",
category=ScrapyDeprecationWarning,
)