From 192b2ea501c93d178c330187093fae5ea9d1f31d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20BRIOL?= Date: Sun, 10 Mar 2024 12:36:26 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20Refactor=20fs=5Fwalk=20fun?= =?UTF-8?q?ction=20to=20improve=20readability=20and=20performance?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zcollection/fs_utils.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/zcollection/fs_utils.py b/zcollection/fs_utils.py index 04674bb..4728300 100644 --- a/zcollection/fs_utils.py +++ b/zcollection/fs_utils.py @@ -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."""