Skip to content

Commit

Permalink
make it a bit faster with generators
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsavio committed Mar 6, 2016
1 parent 884be8d commit 97fd678
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions hansel/crumb.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,9 +553,9 @@ def build_paths(self, values_map, make_crumbs=True):
paths: list of str or list of Crumb
"""
if make_crumbs:
return [self.replace(**dict(val)) for val in values_map]
return (self.replace(**dict(val)) for val in values_map)
else:
return [_build_path(self.path, arg_values=dict(val)) for val in values_map]
return (_build_path(self.path, arg_values=dict(val)) for val in values_map)

def ls(self, arg_name='', fullpath=True, make_crumbs=True, check_exists=True):
""" Return the list of values for the argument crumb `arg_name`.
Expand Down Expand Up @@ -600,7 +600,7 @@ def ls(self, arg_name='', fullpath=True, make_crumbs=True, check_exists=True):
if fullpath:
paths = self.build_paths(values_map, make_crumbs=make_crumbs)
else:
paths = [dict(val)[arg_name] for val in values_map]
paths = (dict(val)[arg_name] for val in values_map)

return sorted(paths)

Expand Down Expand Up @@ -663,7 +663,7 @@ def exists(self):
_, last = self._last_open_arg()
paths = self.ls(last, fullpath=True, make_crumbs=False, check_exists=False)

return any([_split_exists(lp) for lp in paths])
return any((_split_exists(lp) for lp in paths))

def has_files(self):
""" Return True if the current crumb path has any file in its
Expand All @@ -678,7 +678,7 @@ def has_files(self):
_, last = self._last_open_arg()
paths = self.ls(last, fullpath=True, make_crumbs=True, check_exists=True)

return any([op.isfile(str(lp)) for lp in paths])
return any((op.isfile(str(lp)) for lp in paths))

def unfold(self):
""" Return a list of all the existing paths until the last crumb argument.
Expand Down

0 comments on commit 97fd678

Please sign in to comment.