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 bd1b6228d1.

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
Barney Gale 2023-05-29 22:44:51 +01:00 committed by GitHub
parent 39f6a0489f
commit d593074494
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -235,7 +235,7 @@ class _PathParents(Sequence):
return "<{}.parents>".format(type(self._path).__name__) return "<{}.parents>".format(type(self._path).__name__)
class PurePath(os.PathLike): class PurePath:
"""Base class for manipulating paths without I/O. """Base class for manipulating paths without I/O.
PurePath represents a filesystem path and offers operations which PurePath represents a filesystem path and offers operations which
@ -715,6 +715,10 @@ class PurePath(os.PathLike):
return False return False
return True 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): class PurePosixPath(PurePath):
"""PurePath subclass for non-Windows systems. """PurePath subclass for non-Windows systems.