Use autodoc for stats.rst (#7769)

This commit is contained in:
Adrian 2026-07-23 16:48:59 +02:00 committed by GitHub
parent 67e5282684
commit abbc024bbe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 21 deletions

View File

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

View File

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