From 763521e60b09520fb5d3e716f0195116ebbfaba9 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 4 Jun 2026 13:42:01 +1000 Subject: [PATCH] pathlib: Fix glob/rglob to return Path objects rather than strings. This now matches CPython behaviour. Signed-off-by: Damien George --- python-stdlib/pathlib/manifest.py | 2 +- python-stdlib/pathlib/pathlib.py | 2 +- python-stdlib/pathlib/tests/test_pathlib.py | 10 ++++++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/python-stdlib/pathlib/manifest.py b/python-stdlib/pathlib/manifest.py index 37dcaf634..a43122676 100644 --- a/python-stdlib/pathlib/manifest.py +++ b/python-stdlib/pathlib/manifest.py @@ -1,3 +1,3 @@ -metadata(version="0.0.1") +metadata(version="0.0.2") module("pathlib.py") diff --git a/python-stdlib/pathlib/pathlib.py b/python-stdlib/pathlib/pathlib.py index e0f961373..135f069e5 100644 --- a/python-stdlib/pathlib/pathlib.py +++ b/python-stdlib/pathlib/pathlib.py @@ -126,7 +126,7 @@ def _glob(self, path, pattern, recursive): for name, mode, *_ in os.ilistdir(path): full_path = path + _SEP + name if name.startswith(prefix) and name.endswith(suffix): - yield full_path + yield Path(full_path) if recursive and mode & 0x4000: # is_dir yield from self._glob(full_path, pattern, recursive=recursive) diff --git a/python-stdlib/pathlib/tests/test_pathlib.py b/python-stdlib/pathlib/tests/test_pathlib.py index 31e762eea..23d832233 100644 --- a/python-stdlib/pathlib/tests/test_pathlib.py +++ b/python-stdlib/pathlib/tests/test_pathlib.py @@ -164,7 +164,10 @@ def test_glob(self): glob_gen = path.glob("*.txt") self.assertTrue(_isgenerator(glob_gen)) - res = [str(x) for x in glob_gen] + res = list(glob_gen) + for p in res: + self.assertIsInstance(p, Path) + self.assertTrue(len(res) == 2) self.assertTrue(foo_txt in res) self.assertTrue(bar_txt in res) @@ -190,7 +193,10 @@ def test_rglob(self): glob_gen = path.rglob("*.txt") self.assertTrue(_isgenerator(glob_gen)) - res = [str(x) for x in glob_gen] + res = list(glob_gen) + for p in res: + self.assertIsInstance(p, Path) + self.assertTrue(len(res) == 3) self.assertTrue(foo_txt in res) self.assertTrue(bar_txt in res)