Skip to content

Commit

Permalink
Add support for set type
Browse files Browse the repository at this point in the history
  • Loading branch information
ava7 committed May 13, 2024
1 parent 5fe228a commit b01f2f2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions itemloaders/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ def arg_to_iter(arg: Any) -> Iterable[Any]:
If *arg* is a list, a tuple or a generator, it will be returned as is.
If *arg* is a set, it will be casted to a list.
If *arg* is ``None``, an empty list will be returned.
If *arg* is anything else, a list will be returned with *arg* as its only
Expand All @@ -22,6 +24,8 @@ def arg_to_iter(arg: Any) -> Iterable[Any]:
return []
if isinstance(arg, (list, tuple, Generator)):
return arg
if isinstance(arg, set):
return list(arg)
return [arg]


Expand Down
7 changes: 7 additions & 0 deletions tests/test_nested_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ class TestItem:
def test_dict(self):
self._test_item({"foo": "bar"})

def test_set(self):
item = {"foo", "bar"}
il = ItemLoader()
il.add_value("item_list", item)

self.assertEqual(il.load_item(), {"item_list": list(item)})

def test_scrapy_item(self):
try:
from scrapy import Field, Item
Expand Down

0 comments on commit b01f2f2

Please sign in to comment.