From f138bba39153ea20236bf01f9a90d6cca470aee4 Mon Sep 17 00:00:00 2001 From: Adrian Chaves Date: Wed, 5 Aug 2026 20:38:29 +0200 Subject: [PATCH] Use warnings.deprecated --- pyproject.toml | 1 + scrapyrt/core.py | 24 ++++++++++++------------ tox.ini | 1 + 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 46a61de..9606736 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,6 +9,7 @@ description = "Put Scrapy spiders behind an HTTP API" dependencies = [ "scrapy>=2.7", "packaging>=20.0", + 'typing-extensions>=4.5.0; python_version < "3.13"', ] classifiers = [ "Development Status :: 5 - Production/Stable", diff --git a/scrapyrt/core.py b/scrapyrt/core.py index 9703ffb..5b7d8c9 100644 --- a/scrapyrt/core.py +++ b/scrapyrt/core.py @@ -1,6 +1,7 @@ from __future__ import annotations import datetime as dt +import sys from collections import OrderedDict from copy import deepcopy from pathlib import Path @@ -17,6 +18,15 @@ from .conf.spider_settings import get_project_settings, get_scrapyrt_settings from .log import setup_spider_logging +if sys.version_info >= (3, 13): + from warnings import deprecated +else: + from typing_extensions import deprecated + +_START_REQUESTS_DEPRECATED = ( + "CrawlManager.start_requests is deprecated, use CrawlManager.spider_start instead." +) + class ScrapyrtCrawlerRunner(CrawlerRunner): def __init__(self, settings, scrapyrt_manager): @@ -107,23 +117,13 @@ def _init_spider_start(self, start_requests, spider_start): self.spider_start = spider_start @property + @deprecated(_START_REQUESTS_DEPRECATED) def start_requests(self): - warn( - "CrawlManager.start_requests is deprecated, use " - "CrawlManager.spider_start instead.", - DeprecationWarning, - stacklevel=2, - ) return self.spider_start @start_requests.setter + @deprecated(_START_REQUESTS_DEPRECATED) def start_requests(self, value: bool): - warn( - "CrawlManager.start_requests is deprecated, use " - "CrawlManager.spider_start instead.", - DeprecationWarning, - stacklevel=2, - ) self.spider_start = value def crawl(self, *args, **kwargs): diff --git a/tox.ini b/tox.ini index 06a6e84..24bf71f 100644 --- a/tox.ini +++ b/tox.ini @@ -71,6 +71,7 @@ deps = # DeprecationWarning: twisted.web.http.HTTPClient was deprecated in # Twisted 24.7.0: Use twisted.web.client.Agent instead. Twisted<24.7.0 + typing-extensions==4.5.0 [testenv:coverage]