Skip to content

Commit d593074

Browse files
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 bd1b622. Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
1 parent 39f6a04 commit d593074

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Lib/pathlib.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def __repr__(self):
235235
return "<{}.parents>".format(type(self._path).__name__)
236236

237237

238-
class PurePath(os.PathLike):
238+
class PurePath:
239239
"""Base class for manipulating paths without I/O.
240240
241241
PurePath represents a filesystem path and offers operations which
@@ -715,6 +715,10 @@ def match(self, path_pattern, *, case_sensitive=None):
715715
return False
716716
return True
717717

718+
# Subclassing os.PathLike makes isinstance() checks slower,
719+
# which in turn makes Path construction slower. Register instead!
720+
os.PathLike.register(PurePath)
721+
718722

719723
class PurePosixPath(PurePath):
720724
"""PurePath subclass for non-Windows systems.

0 commit comments

Comments
 (0)