mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
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>
This commit is contained in:
parent
3095d02642
commit
a74f117dab
6 changed files with 20 additions and 10 deletions
|
@ -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")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue