We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7457331 commit 67e7297Copy full SHA for 67e7297
web_poet/utils.py
@@ -1,4 +1,5 @@
1
import weakref
2
+from collections.abc import Iterable
3
from functools import wraps
4
from typing import Any, Optional, List
5
@@ -29,9 +30,20 @@ def as_list(value: Optional[Any]) -> List[Any]:
29
30
[123]
31
>>> as_list(["foo", "bar", 123])
32
['foo', 'bar', 123]
33
+ >>> as_list(("foo", "bar", 123))
34
+ ['foo', 'bar', 123]
35
+ >>> as_list(range(5))
36
+ [0, 1, 2, 3, 4]
37
+ >>> def gen():
38
+ ... yield 1
39
+ ... yield 2
40
+ >>> as_list(gen())
41
+ [1, 2]
42
"""
43
if value is None:
44
return []
- if not isinstance(value, list):
45
+ if isinstance(value, str):
46
+ return [value]
47
+ if not isinstance(value, Iterable):
48
return [value]
49
return list(value)
0 commit comments