Scrapy, a fast high-level web crawling & scraping framework for Python.
Make copy.copy() work on Item (#8172)
Adrian991a29e19ffb
diff --git a/scrapy/item.py b/scrapy/item.pyindex 57d2272e2..347f88581 100644--- a/scrapy/item.py+++ b/scrapy/item.py@@ -150,6 +150,8 @@ class Item(MutableMapping[str, Any], object_ref, metaclass=ItemMeta):def copy(self) -> Self:return self.__class__(self)+ __copy__ = copy+def deepcopy(self) -> Self:"""Return a :func:`~copy.deepcopy` of this item."""return deepcopy(self)diff --git a/tests/test_item.py b/tests/test_item.pyindex 45732f157..8e7ea4b58 100644--- a/tests/test_item.py+++ b/tests/test_item.py@@ -1,3 +1,4 @@+import copyfrom abc import ABCMetafrom typing import Anyfrom unittest import mock@@ -291,6 +292,15 @@ class TestItem:copied_item["name"] = copied_item["name"].upper()assert item["name"] != copied_item["name"]+ def test_copy_copy(self):+ class TestItem(Item):+ name = Field()++ item = TestItem({"name": "lower"})+ copied_item = copy.copy(item)+ copied_item["name"] = copied_item["name"].upper()+ assert item["name"] != copied_item["name"]+def test_deepcopy(self):class TestItem(Item):tags = Field()