MCPcopy
hub / github.com/scrapy/scrapy / is_listlike

Function is_listlike

scrapy/utils/python.py:35–56  ·  view source on GitHub ↗

>>> is_listlike("foo") False >>> is_listlike(5) False >>> is_listlike(b"foo") False >>> is_listlike([b"foo"]) True >>> is_listlike((b"foo",)) True >>> is_listlike({}) True >>> is_listlike(set()) True >>> is_listlike((x for x in range(3)))

(x: Any)

Source from the content-addressed store, hash-verified

33
34
35def is_listlike(x: Any) -> bool:
36 """
37 >>> is_listlike("foo")
38 False
39 >>> is_listlike(5)
40 False
41 >>> is_listlike(b"foo")
42 False
43 >>> is_listlike([b"foo"])
44 True
45 >>> is_listlike((b"foo",))
46 True
47 >>> is_listlike({})
48 True
49 >>> is_listlike(set())
50 True
51 >>> is_listlike((x for x in range(3)))
52 True
53 >>> is_listlike(range(5))
54 True
55 """
56 return hasattr(x, "__iter__") and not isinstance(x, (str, bytes))
57
58
59def unique(list_: Iterable[_T], key: Callable[[_T], Any] = lambda x: x) -> list[_T]:

Callers 3

_export_xml_fieldMethod · 0.90
_serialize_valueMethod · 0.90
_urlencodeFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected