File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change 11import weakref
2+ from collections .abc import Iterable
23from functools import wraps
34from typing import Any , Optional , List
45
@@ -29,9 +30,24 @@ def as_list(value: Optional[Any]) -> List[Any]:
2930 [123]
3031 >>> as_list(["foo", "bar", 123])
3132 ['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]
3242 """
3343 if value is None :
3444 return []
35- if not isinstance (value , list ):
45+ if isinstance (value , str ):
46+ return [value ]
47+ if not (
48+ isinstance (value , list )
49+ or isinstance (value , tuple )
50+ or isinstance (value , Iterable )
51+ ):
3652 return [value ]
3753 return list (value )
You can’t perform that action at this time.
0 commit comments