Scrapy, a fast high-level web crawling & scraping framework for Python.
Deprecate PeriodicLog.multiplier instead of removing it altogether (#7982)
Adrian52cc2da72d5b
diff --git a/scrapy/extensions/periodic_log.py b/scrapy/extensions/periodic_log.pyindex adffbcbc4..1b66eae4a 100644--- a/scrapy/extensions/periodic_log.py+++ b/scrapy/extensions/periodic_log.py@@ -1,11 +1,12 @@from __future__ import annotationsimport logging+import warningsfrom datetime import datetime, timezonefrom typing import TYPE_CHECKING, Anyfrom scrapy import Spider, signals-from scrapy.exceptions import NotConfigured+from scrapy.exceptions import NotConfigured, ScrapyDeprecationWarningfrom scrapy.utils.asyncio import AsyncioLoopingCall, create_looping_callfrom scrapy.utils.serialize import ScrapyJSONEncoder@@ -38,6 +39,7 @@ class PeriodicLog:):self.stats: StatsCollector = statsself.interval: float = interval+ self._multiplier: float = 60.0 / intervalself.task: AsyncioLoopingCall | LoopingCall | None = Noneself.encoder: JSONEncoder = ScrapyJSONEncoder(sort_keys=True, indent=4)self.ext_stats_enabled: bool = bool(ext_stats)@@ -56,6 +58,24 @@ class PeriodicLog:)self.ext_timing_enabled: bool = ext_timing_enabled+ @property+ def multiplier(self) -> float:+ warnings.warn(+ "The PeriodicLog.multiplier attribute is deprecated.",+ ScrapyDeprecationWarning,+ stacklevel=2,+ )+ return self._multiplier++ @multiplier.setter+ def multiplier(self, value: float) -> None:+ warnings.warn(+ "The PeriodicLog.multiplier attribute is deprecated.",+ ScrapyDeprecationWarning,+ stacklevel=2,+ )+ self._multiplier = value+@classmethoddef from_crawler(cls, crawler: Crawler) -> Self:interval: float = crawler.settings.getfloat("LOGSTATS_INTERVAL")diff --git a/tests/test_extension_periodic_log.py b/tests/test_extension_periodic_log.pyindex 340f8e28e..fd7e3958d 100644--- a/tests/test_extension_periodic_log.py+++ b/tests/test_extension_periodic_log.py@@ -7,7 +7,7 @@ from typing import TYPE_CHECKING, Anyimport pytest-from scrapy.exceptions import NotConfigured+from scrapy.exceptions import NotConfigured, ScrapyDeprecationWarningfrom scrapy.extensions.periodic_log import PeriodicLogfrom scrapy.utils.misc import build_from_crawlerfrom scrapy.utils.test import get_crawler@@ -249,3 +249,17 @@ class TestPeriodicLog:assert data["time"]["log_interval_real"] >= 0assert data["time"]["elapsed"] >= 0assert data["time"]["start_time"] <= data["time"]["utcnow"]++ def test_multiplier_deprecated(self) -> None:+ crawler = get_crawler(+ MetaSpider,+ {"PERIODIC_LOG_TIMING_ENABLED": True, "LOGSTATS_INTERVAL": 30},+ )+ crawler._apply_settings()+ ext = build_from_crawler(PeriodicLog, crawler)+ with pytest.warns(ScrapyDeprecationWarning):+ assert ext.multiplier == 2.0+ with pytest.warns(ScrapyDeprecationWarning):+ ext.multiplier = 3.0+ with pytest.warns(ScrapyDeprecationWarning):+ assert ext.multiplier == 3.0