Skip to content

Commit 3c604b5

Browse files
committed
Fix pathlib.glob() for Python 3.14
- glob() defines another static method that has to be patched
1 parent ffde08b commit 3c604b5

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ The released versions correspond to PyPI releases.
1717
* changed the default for `FakeFilesystem.shuffle_listdir_results` to `True` to reflect
1818
the real filesystem behavior
1919

20+
### Fixes
21+
* fixed `pathlib.glob()` for Python 3.14 (see [#1239](../../issues/1239))
22+
2023
## [Version 5.10.1](https://pypi.python.org/pypi/pyfakefs/5.10.1) (2025-10-27)
2124
Fixes a regression introduced in version 5.9.0.
2225

pyfakefs/fake_filesystem_unittest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,8 @@ def _set_glob_os_functions(self):
10761076
globber.lstat = staticmethod(os.lstat)
10771077
if sys.version_info < (3, 14):
10781078
globber.scandir = staticmethod(os.scandir)
1079+
if sys.version_info >= (3, 14):
1080+
globber.lexists = staticmethod(os.path.lexists)
10791081

10801082
def patch_functions(self) -> None:
10811083
assert self._stubs is not None

pyfakefs/tests/fake_pathlib_test.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,13 @@ def test_glob(self):
973973
sorted(path.glob("*.py")),
974974
)
975975

976+
def test_glob_dir(self):
977+
# regression test for #1239
978+
root_dir = self.path(self.make_path("root"))
979+
test_file = self.make_path(root_dir, "foo", "bar.txt")
980+
self.create_file(test_file)
981+
self.assertEqual([root_dir / "foo"], list(root_dir.glob("foo")))
982+
976983
def test_glob_case_windows(self):
977984
self.check_windows_only()
978985
self.create_file(self.make_path("foo", "setup.py"))

0 commit comments

Comments
 (0)