summaryrefslogtreecommitdiffstats
path: root/Lib/pathlib
diff options
context:
space:
mode:
authorBarney Gale <barney.gale@gmail.com>2024-01-08 19:31:52 (GMT)
committerGitHub <noreply@github.com>2024-01-08 19:31:52 (GMT)
commitb3dba18eab96dc95653031863bb2a222af912f2b (patch)
tree99b47c48bba41f56492fdaa18a36ad478eaa12da /Lib/pathlib
parentbc71ae2b97bb59b1796be056fb821d9abdee840b (diff)
downloadcpython-b3dba18eab96dc95653031863bb2a222af912f2b.zip
cpython-b3dba18eab96dc95653031863bb2a222af912f2b.tar.gz
cpython-b3dba18eab96dc95653031863bb2a222af912f2b.tar.bz2
GH-113528: Speed up pathlib ABC tests. (#113788)
- Add `__slots__` to dummy path classes. - Return namedtuple rather than `os.stat_result` from `DummyPath.stat()`. - Reduce maximum symlink count in `DummyPathWithSymlinks.resolve()`.
Diffstat (limited to 'Lib/pathlib')
-rw-r--r--Lib/pathlib/_abc.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/Lib/pathlib/_abc.py b/Lib/pathlib/_abc.py
index 97663b9..be22ece 100644
--- a/Lib/pathlib/_abc.py
+++ b/Lib/pathlib/_abc.py
@@ -10,9 +10,6 @@ from stat import S_ISDIR, S_ISLNK, S_ISREG, S_ISSOCK, S_ISBLK, S_ISCHR, S_ISFIFO
# Internals
#
-# Maximum number of symlinks to follow in PathBase.resolve()
-_MAX_SYMLINKS = 40
-
# Reference for Windows paths can be found at
# https://learn.microsoft.com/en-gb/windows/win32/fileio/naming-a-file .
_WIN_RESERVED_NAMES = frozenset(
@@ -500,6 +497,9 @@ class PathBase(PurePathBase):
"""
__slots__ = ()
+ # Maximum number of symlinks to follow in resolve()
+ _max_symlinks = 40
+
@classmethod
def _unsupported(cls, method_name):
msg = f"{cls.__name__}.{method_name}() is unsupported"
@@ -971,7 +971,7 @@ class PathBase(PurePathBase):
# Like Linux and macOS, raise OSError(errno.ELOOP) if too many symlinks are
# encountered during resolution.
link_count += 1
- if link_count >= _MAX_SYMLINKS:
+ if link_count >= self._max_symlinks:
raise OSError(ELOOP, "Too many symbolic links in path", str(self))
target, target_parts = next_path.readlink()._split_stack()
# If the symlink target is absolute (like '/etc/hosts'), set the current