From 8f37307c69b9e391a01cf1dba73ca342faf07175 Mon Sep 17 00:00:00 2001 From: Marc <88182556+marcm-ml@users.noreply.github.com> Date: Sat, 28 Feb 2026 11:18:00 +0000 Subject: [PATCH 1/2] fix: allow withdirs parameter in glob for AbstractFileSystem --- fsspec/spec.py | 3 ++- fsspec/tests/test_spec.py | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/fsspec/spec.py b/fsspec/spec.py index b67d5c16f..519da9e70 100644 --- a/fsspec/spec.py +++ b/fsspec/spec.py @@ -611,6 +611,7 @@ def glob(self, path, maxdepth=None, **kwargs): min_idx = min(idx_star, idx_qmark, idx_brace) detail = kwargs.pop("detail", False) + withdirs = kwargs.pop("withdirs", True) if not has_magic(path): if self.exists(path, **kwargs): @@ -639,7 +640,7 @@ def glob(self, path, maxdepth=None, **kwargs): else: depth = None - allpaths = self.find(root, maxdepth=depth, withdirs=True, detail=True, **kwargs) + allpaths = self.find(root, maxdepth=depth, withdirs=withdirs, detail=True, **kwargs) pattern = glob_translate(path + ("/" if ends_with_sep else "")) pattern = re.compile(pattern) diff --git a/fsspec/tests/test_spec.py b/fsspec/tests/test_spec.py index dafb0d004..40079bbb1 100644 --- a/fsspec/tests/test_spec.py +++ b/fsspec/tests/test_spec.py @@ -1376,6 +1376,15 @@ def test_glob_posix_rules(path, expected, glob_fs): for name, info in _clean_paths(detailed_output).items(): assert info == glob_fs[name] + withdirs_output = glob_fs.glob(path=f"mock://{path}", detail=True, withdirs=False) + path_output = _clean_paths(withdirs_output) + for name, info in path_output.items(): + # withdirs only respected when path has magic + # otherwise glob returns the path regardless of the type of the path + if glob.has_magic(path): + assert info["type"] == "file" + assert info == glob_fs[name] + @pytest.fixture(scope="function") def tmpfs(tmpdir): From 79fe8fa04ae98e423699dd980b90a0dd4b90bd22 Mon Sep 17 00:00:00 2001 From: Marc <88182556+marcm-ml@users.noreply.github.com> Date: Mon, 23 Mar 2026 12:32:24 +0000 Subject: [PATCH 2/2] fix lint --- fsspec/spec.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fsspec/spec.py b/fsspec/spec.py index 519da9e70..237391eb9 100644 --- a/fsspec/spec.py +++ b/fsspec/spec.py @@ -640,7 +640,9 @@ def glob(self, path, maxdepth=None, **kwargs): else: depth = None - allpaths = self.find(root, maxdepth=depth, withdirs=withdirs, detail=True, **kwargs) + allpaths = self.find( + root, maxdepth=depth, withdirs=withdirs, detail=True, **kwargs + ) pattern = glob_translate(path + ("/" if ends_with_sep else "")) pattern = re.compile(pattern)