mirror of https://github.com/scrapy/scrapy.git
Deprecate build_from_crawler() calling from_settings().
This commit is contained in:
parent
eda1a8a7c5
commit
8700a5b7a9
|
|
@ -54,6 +54,14 @@ 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:
|
||||
|
|
|
|||
|
|
@ -185,6 +185,14 @@ def build_from_crawler(
|
|||
instance = objcls.from_crawler(crawler, *args, **kwargs) # type: ignore[attr-defined]
|
||||
method_name = "from_crawler"
|
||||
elif 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(crawler.settings, *args, **kwargs) # type: ignore[attr-defined]
|
||||
method_name = "from_settings"
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ from weakref import WeakKeyDictionary
|
|||
|
||||
import pytest
|
||||
|
||||
from scrapy.exceptions import ScrapyDeprecationWarning
|
||||
from scrapy.http import Request
|
||||
from scrapy.utils.python import to_bytes
|
||||
from scrapy.utils.request import (
|
||||
|
|
@ -384,7 +385,9 @@ class CustomRequestFingerprinterTestCase(unittest.TestCase):
|
|||
"REQUEST_FINGERPRINTER_CLASS": RequestFingerprinter,
|
||||
"FINGERPRINT": b"fingerprint",
|
||||
}
|
||||
crawler = get_crawler(settings_dict=settings)
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", ScrapyDeprecationWarning)
|
||||
crawler = get_crawler(settings_dict=settings)
|
||||
|
||||
request = Request("http://www.example.com")
|
||||
fingerprint = crawler.request_fingerprinter.fingerprint(request)
|
||||
|
|
|
|||
Loading…
Reference in New Issue