]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
GH-115060: Speed up `pathlib.Path.glob()` by omitting initial `stat()` (#117831)
authorBarney Gale <barney.gale@gmail.com>
Sat, 13 Apr 2024 23:08:03 +0000 (00:08 +0100)
committerGitHub <noreply@github.com>
Sat, 13 Apr 2024 23:08:03 +0000 (00:08 +0100)
commita74f117dab369e6c54156c7b2256769fed0c23d0
tree6db14d7a5be43aadca9df39cb304141f5322dcf8
parent3095d026424f11714f0b7a828c61dc741d4e716b
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>
Doc/library/pathlib.rst
Lib/pathlib/__init__.py
Lib/pathlib/_abc.py
Lib/test/test_pathlib/test_pathlib.py
Lib/test/test_pathlib/test_pathlib_abc.py
Misc/NEWS.d/next/Library/2024-04-13-01-45-15.gh-issue-115060.IxoM03.rst [new file with mode: 0644]