Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for set type #84

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading