diff --git a/docs/topics/stats.rst b/docs/topics/stats.rst index 028fb009d..0cf4a72cc 100644 --- a/docs/topics/stats.rst +++ b/docs/topics/stats.rst @@ -94,27 +94,10 @@ default Stats Collector used is the :class:`MemoryStatsCollector`. MemoryStatsCollector -------------------- -.. class:: MemoryStatsCollector - - A simple stats collector that keeps the stats of the last scraping run (for - each spider) in memory, after they're closed. The stats can be accessed - through the :attr:`spider_stats` attribute, which is a dict keyed by spider - name. - - This is the default Stats Collector used in Scrapy. - - .. attribute:: spider_stats - - A dict of dicts (keyed by spider name) containing the stats of the last - scraping run for each spider. +.. autoclass:: MemoryStatsCollector + :members: DummyStatsCollector ------------------- -.. class:: DummyStatsCollector - - A Stats collector which does nothing but is very efficient (because it does - nothing). This stats collector can be set via the :setting:`STATS_CLASS` - setting, to disable stats collect in order to improve performance. However, - the performance penalty of stats collection is usually marginal compared to - other Scrapy workload like parsing pages. +.. autoclass:: DummyStatsCollector diff --git a/scrapy/statscollectors.py b/scrapy/statscollectors.py index 1f9894519..3143fed63 100644 --- a/scrapy/statscollectors.py +++ b/scrapy/statscollectors.py @@ -101,9 +101,21 @@ class StatsCollector: class MemoryStatsCollector(StatsCollector): + """A simple stats collector that keeps the stats of the last scraping run + (for each spider) in memory, after they're closed. The stats can be + accessed through the :attr:`spider_stats` attribute, which is a dict keyed + by spider name. + + This is the default stats collector used in Scrapy. + """ + + spider_stats: dict[str, StatsT] + """A dict of dicts (keyed by spider name) containing the stats of the last + scraping run for each spider.""" + def __init__(self, crawler: Crawler): super().__init__(crawler) - self.spider_stats: dict[str, StatsT] = {} + self.spider_stats = {} def _persist_stats(self, stats: StatsT) -> None: if self._crawler.spider: @@ -111,6 +123,13 @@ class MemoryStatsCollector(StatsCollector): class DummyStatsCollector(StatsCollector): + """A stats collector which does nothing but is very efficient (because it + does nothing). This stats collector can be set via the + :setting:`STATS_CLASS` setting, to disable stats collection in order to + improve performance. However, the performance penalty of stats collection + is usually marginal compared to other Scrapy workload like parsing pages. + """ + def get_value( self, key: str, default: Any = None, spider: Spider | None = None ) -> Any: