]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-104898: Revert pathlib os.PathLike registration change. (GH-105073)
authorBarney Gale <barney.gale@gmail.com>
Mon, 29 May 2023 21:44:51 +0000 (22:44 +0100)
committerGitHub <noreply@github.com>
Mon, 29 May 2023 21:44:51 +0000 (21:44 +0000)
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>
Lib/pathlib.py

index 87c2e970a0a881a71fa7d663fec967ad8f9f4cce..a57b582a211e06681e82dfd3433ef647673d256b 100644 (file)
@@ -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.