Skip to content

Commit

Permalink
Merge branch 'fixes'
Browse files Browse the repository at this point in the history
* features:
  Bump to version 0.42.5
  [FIX] Identify iterators and generators as listlike
  • Loading branch information
reubano committed Jul 29, 2020
2 parents 23faffd + 1f00dd4 commit ff1f881
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion meza/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from datetime import datetime as dt
from os import path as p

__version__ = '0.42.4'
__version__ = '0.42.5'
__title__ = 'meza'
__package_name__ = 'meza'
__author__ = 'Reuben Cummings'
Expand Down
20 changes: 19 additions & 1 deletion meza/fntools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1106,10 +1106,28 @@ def remove_keys(record, *args):


def listize(item):
""" Create a listlike object from an item
Args:
item (dict): The object to convert
Returns:
Seq: Item as a listlike object
Examples:
>>> listize(x for x in range(3)) # doctest: +ELLIPSIS
<generator object <genexpr> at 0x...>
>>> listize([x for x in range(3)])
[0, 1, 2]
>>> listize(iter(x for x in range(3))) # doctest: +ELLIPSIS
<generator object <genexpr> at 0x...>
>>> listize(range(3))
range(0, 3)
"""
if hasattr(item, 'keys'):
listlike = False
else:
attrs = {'append', 'next', '__reversed__'}
attrs = {'append', 'next', '__reversed__', '__next__'}
listlike = attrs.intersection(dir(item))

return item if listlike else [item]
Expand Down

0 comments on commit ff1f881

Please sign in to comment.