From 044c3f69edd1bf926408649361ada7f2146db04e Mon Sep 17 00:00:00 2001 From: Mehraz Hossain Rumman <59512321+MehrazRumman@users.noreply.github.com> Date: Mon, 10 Mar 2025 01:18:57 +0600 Subject: [PATCH] Deprecate InitSpider (#6714) --- scrapy/spiders/init.py | 17 ++++++++++++++++- tests/test_spider.py | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/scrapy/spiders/init.py b/scrapy/spiders/init.py index 4ec2919f7..a7dba989e 100644 --- a/scrapy/spiders/init.py +++ b/scrapy/spiders/init.py @@ -1,9 +1,11 @@ from __future__ import annotations +import warnings from collections.abc import Iterable from typing import TYPE_CHECKING, Any, cast from scrapy import Request +from scrapy.exceptions import ScrapyDeprecationWarning from scrapy.spiders import Spider from scrapy.utils.spider import iterate_spider_output @@ -12,7 +14,20 @@ if TYPE_CHECKING: class InitSpider(Spider): - """Base Spider with initialization facilities""" + """Base Spider with initialization facilities + + .. warning:: This class is deprecated. Copy its code into your project if needed. + It will be removed in a future Scrapy version. + """ + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + warnings.warn( + "InitSpider is deprecated. Copy its code from Scrapy's source if needed. " + "Will be removed in a future version.", + ScrapyDeprecationWarning, + stacklevel=2, + ) def start_requests(self) -> Iterable[Request]: self._postinit_reqs: Iterable[Request] = super().start_requests() diff --git a/tests/test_spider.py b/tests/test_spider.py index 05f1c59d0..4e8330c06 100644 --- a/tests/test_spider.py +++ b/tests/test_spider.py @@ -144,6 +144,7 @@ class TestSpider(unittest.TestCase): mock_logger.log.assert_called_once_with("INFO", "test log msg") +@pytest.mark.filterwarnings("ignore::scrapy.exceptions.ScrapyDeprecationWarning") class TestInitSpider(TestSpider): spider_class = InitSpider