Skip to content

Commit

Permalink
⚡️ Refactor fs_walk function to improve readability and performance
Browse files Browse the repository at this point in the history
  • Loading branch information
fbriol committed Mar 10, 2024
1 parent 7b580a5 commit 192b2ea
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions zcollection/fs_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,12 @@ def fs_walk(
yield '', [], []
return

for info in listing:
for is_dir, name in ((info['type'] == 'directory', info['name'])
for info in listing):
# each info name must be at least [path]/part , but here
# we check also for names like [path]/part/
pathname: str = info['name'].rstrip(SEPARATOR)
name: str = pathname.rsplit(SEPARATOR, 1)[-1]
if info['type'] == 'directory' and pathname != path:
# do not include "self" path
dirs.append(pathname)
else:
files.append(name)
dirs.append(name) if is_dir else files.append(
name.rsplit(SEPARATOR, 1)[-1])

def sort_sequence(sequence: list[str]) -> list[str]:
"""Sort the sequence if the user wishes."""
Expand Down

0 comments on commit 192b2ea

Please sign in to comment.