Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

changing dunder-str to dunder-repr

Gustavo Bordin5bacc4822e80
diff --git a/scrapy/core/http2/stream.py b/scrapy/core/http2/stream.py
index c2a4b702f..a3a9e5e1d 100644
--- a/scrapy/core/http2/stream.py
+++ b/scrapy/core/http2/stream.py
@@ -150,12 +150,10 @@ class Stream:
self.close(StreamCloseReason.CANCELLED)
self._deferred_response = Deferred(_cancel)
-
- def __str__(self) -> str:
+
+ def __repr__(self):
return f'Stream(id={self.stream_id!r})'
- __repr__ = __str__
-
@property
def _log_warnsize(self) -> bool:
"""Checks if we have received data which exceeds the download warnsize
diff --git a/scrapy/http/request/__init__.py b/scrapy/http/request/__init__.py
index ad884feac..a1857c604 100644
--- a/scrapy/http/request/__init__.py
+++ b/scrapy/http/request/__init__.py
@@ -109,11 +109,9 @@ class Request(object_ref):
def encoding(self):
return self._encoding
- def __str__(self):
+ def __repr__(self):
return f"<{self.method} {self.url}>"
- __repr__ = __str__
-
def copy(self):
"""Return a copy of this Request"""
return self.replace()
diff --git a/scrapy/http/response/__init__.py b/scrapy/http/response/__init__.py
index 185a9bb67..eb80c5214 100644
--- a/scrapy/http/response/__init__.py
+++ b/scrapy/http/response/__init__.py
@@ -87,11 +87,9 @@ class Response(object_ref):
body = property(_get_body, obsolete_setter(_set_body, 'body'))
- def __str__(self):
+ def __repr__(self):
return f"<{self.status} {self.url}>"
- __repr__ = __str__
-
def copy(self):
"""Return a copy of this Response"""
return self.replace()
diff --git a/scrapy/settings/__init__.py b/scrapy/settings/__init__.py
index 1fe1e6fd1..69d0476eb 100644
--- a/scrapy/settings/__init__.py
+++ b/scrapy/settings/__init__.py
@@ -51,11 +51,9 @@ class SettingsAttribute:
self.value = value
self.priority = priority
- def __str__(self):
+ def __repr__(self):
return f"<SettingsAttribute value={self.value!r} priority={self.priority}>"
- __repr__ = __str__
-
class BaseSettings(MutableMapping):
"""
diff --git a/scrapy/spiders/__init__.py b/scrapy/spiders/__init__.py
index c13ba4b3c..1c079ff27 100644
--- a/scrapy/spiders/__init__.py
+++ b/scrapy/spiders/__init__.py
@@ -106,11 +106,9 @@ class Spider(object_ref):
if callable(closed):
return closed(reason)
- def __str__(self):
+ def __repr__(self):
return f"<{type(self).__name__} {self.name!r} at 0x{id(self):0x}>"
- __repr__ = __str__
-
# Top-level imports
from scrapy.spiders.crawl import CrawlSpider, Rule