Skip to content

Commit

Permalink
Replace most of always_iterable with version as found in more_itertools.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Oct 6, 2017
1 parent 8a80a1d commit 5a3655e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
7 changes: 7 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
2.1
===

* Use ``more_itertools.more.always_iterable`` in place
of ``always_iterable`` except when a mapping is
included.

2.0.1
=====

Expand Down
13 changes: 6 additions & 7 deletions jaraco/itertools.py
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,7 @@ def reverse_lists(lists):

return list(map(list, map(reversed, lists)))


def always_iterable(item):
"""
Given an object, always return an iterable. If the item is not
Expand All @@ -853,14 +854,12 @@ def always_iterable(item):
>>> always_iterable(dict(a=1))
({'a': 1},)
"""
if item is None:
item = ()
singleton = (
isinstance(item, six.string_types)
or isinstance(item, collections.Mapping)
or not hasattr(item, '__iter__')
return (
(item,)
if isinstance(item, collections.Mapping)
else more.always_iterable(item)
)
return (item,) if singleton else item


def suppress_exceptions(callables, *exceptions):
"""
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
python_requires='>=2.7',
install_requires=[
'six',
'more_itertools',
'more_itertools>=2.6',
'inflect',
],
extras_require={
Expand Down

0 comments on commit 5a3655e

Please sign in to comment.