Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

Deprecate InitSpider (#6714)

Mehraz Hossain Rumman044c3f69edd1
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")
[email protected]("ignore::scrapy.exceptions.ScrapyDeprecationWarning")
class TestInitSpider(TestSpider):
spider_class = InitSpider