From 8eabb1ba5678018b69987e2d034355d79d4013a7 Mon Sep 17 00:00:00 2001 From: brecht stamper Date: Tue, 2 Apr 2024 11:59:33 +0200 Subject: [PATCH] better typing --- scrapy/crawler.py | 2 +- scrapy/http/response/__init__.py | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/scrapy/crawler.py b/scrapy/crawler.py index d00b9ccf64b..ac77d6aefcc 100644 --- a/scrapy/crawler.py +++ b/scrapy/crawler.py @@ -88,7 +88,7 @@ def __init__( self.stats: Optional[StatsCollector] = None self.logformatter: Optional[LogFormatter] = None self.request_fingerprinter: Optional[RequestFingerprinter] = None - self.spider: Optional[Spider] = None + self.spider: Optional[S] = None self.engine: Optional[ExecutionEngine] = None def _update_root_log_handler(self) -> None: diff --git a/scrapy/http/response/__init__.py b/scrapy/http/response/__init__.py index a82ed834a21..36cc3eef77b 100644 --- a/scrapy/http/response/__init__.py +++ b/scrapy/http/response/__init__.py @@ -91,7 +91,14 @@ def _set_url(self, url: str): f"{type(self).__name__} url must be str, " f"got {type(url).__name__}" ) - url = property(_get_url, obsolete_setter(_set_url, "url")) + @property + def url(self): + return self._get_url() + + @url.setter + def url(self, value: str): + setter = obsolete_setter(self._set_url, "url") + setter(self, value) def _get_body(self): return self._body @@ -108,7 +115,14 @@ def _set_body(self, body): else: self._body = body - body = property(_get_body, obsolete_setter(_set_body, "body")) + @property + def body(self): + return self._get_body() + + @body.setter + def body(self, value: bytes): + setter = obsolete_setter(self._set_body, "body") + setter(self, value) def __repr__(self): return f"<{self.status} {self.url}>"