]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
GH-117586: Speed up `pathlib.Path.glob()` by working with strings (#117589)
authorBarney Gale <barney.gale@gmail.com>
Wed, 10 Apr 2024 19:43:07 +0000 (20:43 +0100)
committerGitHub <noreply@github.com>
Wed, 10 Apr 2024 19:43:07 +0000 (20:43 +0100)
commit6258844c27e3b5a43816e7c559089a5fe0a47123
treea5a9a80f60f3bd15f546322cc717f280fb95bf21
parent689ada79150f28b0053fa6c1fb646b75ab2cc200
GH-117586: Speed up `pathlib.Path.glob()` by working with strings (#117589)

Move pathlib globbing implementation into a new private class: `glob._Globber`. This class implements fast string-based globbing. It's called by `pathlib.Path.glob()`, which then converts strings back to path objects.

In the private pathlib ABCs, add a `pathlib._abc.Globber` subclass that works with `PathBase` objects rather than strings, and calls user-defined path methods like `PathBase.stat()` rather than `os.stat()`.

This sets the stage for two more improvements:

- GH-115060: Query non-wildcard segments with `lstat()`
- GH-116380: Unify `pathlib` and `glob` implementations of globbing.

No change to the implementations of `glob.glob()` and `glob.iglob()`.
Lib/glob.py
Lib/pathlib/__init__.py
Lib/pathlib/_abc.py
Misc/NEWS.d/next/Library/2024-04-06-20-31-09.gh-issue-117586.UgWdRK.rst [new file with mode: 0644]