Deprecate InitSpider (#6714)

This commit is contained in:
Mehraz Hossain Rumman 2025-03-10 01:18:57 +06:00 committed by GitHub
parent 1469b2739e
commit 044c3f69ed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 1 deletions

View File

@ -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()

View File

@ -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