From a74f117dab369e6c54156c7b2256769fed0c23d0 Mon Sep 17 00:00:00 2001 From: Barney Gale Date: Sun, 14 Apr 2024 00:08:03 +0100 Subject: GH-115060: Speed up `pathlib.Path.glob()` by omitting initial `stat()` (#117831) Since 6258844c, paths that might not exist can be fed into pathlib's globbing implementation, which will call `os.scandir()` / `os.lstat()` only when strictly necessary. This allows us to drop an initial `self.is_dir()` call, which saves a `stat()`. Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com> --- Lib/test/test_pathlib/test_pathlib.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'Lib/test/test_pathlib/test_pathlib.py') diff --git a/Lib/test/test_pathlib/test_pathlib.py b/Lib/test/test_pathlib/test_pathlib.py index 651d66656cb..5fd1a41cbee 100644 --- a/Lib/test/test_pathlib/test_pathlib.py +++ b/Lib/test/test_pathlib/test_pathlib.py @@ -1263,6 +1263,13 @@ class PathTest(test_pathlib_abc.DummyPathTest, PurePathTest): self.assertEqual( set(P('.').glob('**/*/*')), {P("dirD/fileD")}) + def test_glob_inaccessible(self): + P = self.cls + p = P(self.base, "mydir1", "mydir2") + p.mkdir(parents=True) + p.parent.chmod(0) + self.assertEqual(set(p.glob('*')), set()) + def test_rglob_pathlike(self): P = self.cls p = P(self.base, "dirC") -- cgit v1.2.3