diff --git a/README.md b/README.md index ae32b0a..26f957f 100644 --- a/README.md +++ b/README.md @@ -151,11 +151,12 @@ interface, providing a `dict`-like API to manipulate data for the object it wrap **Attributes** -#### class attribute `ADAPTER_CLASSES: collections.deque` +#### class attribute `ADAPTER_CLASSES: Iterable` -Stores the currently registered adapter classes. Being a -[`collections.deque`](https://docs.python.org/3/library/collections.html#collections.deque), -it supports efficient addition/deletion of adapters classes to both ends. +Stores the currently registered adapter classes. The default implementaion uses a +[`collections.deque`](https://docs.python.org/3/library/collections.html#collections.deque) +to support efficient addition/deletion of adapters classes to both ends, but any other iterable +(e.g. `list`, `tuple`) will work. The order in which the adapters are registered is important. When an `ItemAdapter` object is created for a specific item, the registered adapters are traversed in order and the first @@ -383,7 +384,6 @@ attribute as needed: **Example** ```python ->>> from collections import deque >>> from itemadapter.adapter import ( ... ItemAdapter, ... AttrsAdapter, @@ -395,10 +395,10 @@ attribute as needed: >>> from scrapy.item import Item, Field >>> >>> class BuiltinTypesItemAdapter(ItemAdapter): -... ADAPTER_CLASSES = deque([DictAdapter, DataclassAdapter]) +... ADAPTER_CLASSES = [DictAdapter, DataclassAdapter] ... >>> class ThirdPartyTypesItemAdapter(ItemAdapter): -... ADAPTER_CLASSES = deque([AttrsAdapter, PydanticAdapter, ScrapyItemAdapter]) +... ADAPTER_CLASSES = [AttrsAdapter, PydanticAdapter, ScrapyItemAdapter] ... >>> class ScrapyItem(Item): ... foo = Field() diff --git a/itemadapter/adapter.py b/itemadapter/adapter.py index f7ac90d..3105748 100644 --- a/itemadapter/adapter.py +++ b/itemadapter/adapter.py @@ -3,7 +3,7 @@ from collections import deque from collections.abc import KeysView, MutableMapping from types import MappingProxyType -from typing import Any, Deque, Iterator, Type, Optional, List +from typing import Any, Iterable, Iterator, Type, Optional, List from itemadapter.utils import ( _get_pydantic_model_metadata, @@ -271,7 +271,7 @@ class ItemAdapter(MutableMapping): to extract and set data without having to take the object's type into account. """ - ADAPTER_CLASSES: Deque[Type[AdapterInterface]] = deque( + ADAPTER_CLASSES: Iterable[Type[AdapterInterface]] = deque( [ ScrapyItemAdapter, DictAdapter, diff --git a/tests/test_itemadapter.py b/tests/test_itemadapter.py index 91f7a21..6d5598f 100644 --- a/tests/test_itemadapter.py +++ b/tests/test_itemadapter.py @@ -1,11 +1,10 @@ import unittest -from collections import deque from itemadapter.adapter import ItemAdapter, DictAdapter class DictOnlyItemAdapter(ItemAdapter): - ADAPTER_CLASSES = deque([DictAdapter]) + ADAPTER_CLASSES = [DictAdapter] class ItemAdapterTestCase(unittest.TestCase):