mirror of https://github.com/flaggo/pydu.git
add itercompat.is_iterable for checking iterables
This commit is contained in:
parent
bc499168ad
commit
77bab1f07f
|
@ -0,0 +1,8 @@
|
|||
def is_iterable(x):
|
||||
"An implementation independent way of checking for iterables"
|
||||
try:
|
||||
iter(x)
|
||||
except TypeError:
|
||||
return False
|
||||
else:
|
||||
return True
|
|
@ -0,0 +1,9 @@
|
|||
from pydu.itercompat import is_iterable
|
||||
|
||||
|
||||
def test_is_iterable():
|
||||
assert is_iterable(list())
|
||||
assert is_iterable(tuple())
|
||||
assert is_iterable(dict())
|
||||
assert is_iterable(set())
|
||||
assert not is_iterable(1)
|
Loading…
Reference in New Issue