pathlib.Path.glob() calls os.scandir() under the hood, converting os.DirEntry objects to path objects using a private _make_child_relpath() method. This builds a child path from a given basename. The basename is obtained from the dir entry's name attribute.
I've just spotted (or realised) that dir entries have a path attribute that we could use, rather than constructing our own string path from the basename. This seems to be a fair bit faster in my testing.
Linked PRs
pathlib.Path.glob()callsos.scandir()under the hood, convertingos.DirEntryobjects to path objects using a private_make_child_relpath()method. This builds a child path from a given basename. The basename is obtained from the dir entry'snameattribute.I've just spotted (or realised) that dir entries have a
pathattribute that we could use, rather than constructing our own string path from the basename. This seems to be a fair bit faster in my testing.Linked PRs
pathlib.Path.glob()#113226pathlib._abc.PathBase.glob()#113556pathlib.Path.walk(top_down=False)#113693