Skip to content

Commit 87d37e3

Browse files
committed
GH-125413: pathlib ABCs: use caching path.info.exists() when globbing
Call `ReadablePath.info.exists()` rather than `ReadablePath.exists()` when globbing so that we use (or populate) the `info` cache.
1 parent d88677a commit 87d37e3

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

Lib/glob.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,9 @@ class _PathGlobber(_GlobberBase):
533533
"""Provides shell-style pattern matching and globbing for pathlib paths.
534534
"""
535535

536-
lexists = operator.methodcaller('exists', follow_symlinks=False)
536+
@staticmethod
537+
def lexists(path):
538+
return path.info.exists(follow_symlinks=False)
537539

538540
@staticmethod
539541
def scandir(path):

Lib/test/test_pathlib/test_pathlib_abc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,7 @@ def test_glob_posix(self):
11071107
p = P(self.base)
11081108
q = p / "FILEa"
11091109
given = set(p.glob("FILEa"))
1110-
expect = {q} if q.exists() else set()
1110+
expect = {q} if q.info.exists() else set()
11111111
self.assertEqual(given, expect)
11121112
self.assertEqual(set(p.glob("FILEa*")), set())
11131113

0 commit comments

Comments
 (0)