summaryrefslogtreecommitdiffstats
path: root/Lib/pathlib
diff options
context:
space:
mode:
authorBarney Gale <barney.gale@gmail.com>2024-11-01 17:48:58 (GMT)
committerGitHub <noreply@github.com>2024-11-01 17:48:58 (GMT)
commit68a51e0178e86be8b697683fd108aa795f235507 (patch)
tree5da4b56ce369b38bc7e8398c74a050dd36da105b /Lib/pathlib
parent464a7a91d0c75241a2f1913e78dbfbc29d4193b4 (diff)
downloadcpython-68a51e0178e86be8b697683fd108aa795f235507.zip
cpython-68a51e0178e86be8b697683fd108aa795f235507.tar.gz
cpython-68a51e0178e86be8b697683fd108aa795f235507.tar.bz2
GH-125413: pathlib ABCs: use `scandir()` to speed up `glob()` (#126261)
Use the new `PathBase.scandir()` method in `PathBase.glob()`, which greatly reduces the number of `PathBase.stat()` calls needed when globbing. There are no user-facing changes, because the pathlib ABCs are still private and `Path.glob()` doesn't use the implementation in its superclass.
Diffstat (limited to 'Lib/pathlib')
-rw-r--r--Lib/pathlib/_abc.py14
1 files changed, 1 insertions, 13 deletions
diff --git a/Lib/pathlib/_abc.py b/Lib/pathlib/_abc.py
index dfff8b4..cc7c199 100644
--- a/Lib/pathlib/_abc.py
+++ b/Lib/pathlib/_abc.py
@@ -94,25 +94,13 @@ class PathGlobber(_GlobberBase):
lexists = operator.methodcaller('exists', follow_symlinks=False)
add_slash = operator.methodcaller('joinpath', '')
-
- @staticmethod
- def scandir(path):
- """Emulates os.scandir(), which returns an object that can be used as
- a context manager. This method is called by walk() and glob().
- """
- import contextlib
- return contextlib.nullcontext(path.iterdir())
+ scandir = operator.methodcaller('scandir')
@staticmethod
def concat_path(path, text):
"""Appends text to the given path."""
return path.with_segments(path._raw_path + text)
- @staticmethod
- def parse_entry(entry):
- """Returns the path of an entry yielded from scandir()."""
- return entry
-
class PurePathBase:
"""Base class for pure path objects.