summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBarney Gale <barney.gale@gmail.com>2023-05-29 21:44:51 (GMT)
committerGitHub <noreply@github.com>2023-05-29 21:44:51 (GMT)
commitd593074494b39a3d51e67a4e57189c530867a7ff (patch)
treec0eb0b5053fe6d9cd630029f6287853eeb152ecf
parent39f6a0489fcc815a578d27dfee2feea003c896f8 (diff)
downloadcpython-d593074494b39a3d51e67a4e57189c530867a7ff.zip
cpython-d593074494b39a3d51e67a4e57189c530867a7ff.tar.gz
cpython-d593074494b39a3d51e67a4e57189c530867a7ff.tar.bz2
GH-104898: Revert pathlib os.PathLike registration change. (GH-105073)
Subclassing `os.PathLike` rather than using `register()` makes initialisation slower, due to the additional `__isinstance__` work. This partially reverts commit bd1b6228d132b8e9836fe352cd8dca2b6c1bd98c. Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
-rw-r--r--Lib/pathlib.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/Lib/pathlib.py b/Lib/pathlib.py
index 87c2e97..a57b582 100644
--- a/Lib/pathlib.py
+++ b/Lib/pathlib.py
@@ -235,7 +235,7 @@ class _PathParents(Sequence):
return "<{}.parents>".format(type(self._path).__name__)
-class PurePath(os.PathLike):
+class PurePath:
"""Base class for manipulating paths without I/O.
PurePath represents a filesystem path and offers operations which
@@ -715,6 +715,10 @@ class PurePath(os.PathLike):
return False
return True
+# Subclassing os.PathLike makes isinstance() checks slower,
+# which in turn makes Path construction slower. Register instead!
+os.PathLike.register(PurePath)
+
class PurePosixPath(PurePath):
"""PurePath subclass for non-Windows systems.