Skip to content

Commit

Permalink
pythonGH-104898: Revert pathlib os.PathLike registration change. (pyt…
Browse files Browse the repository at this point in the history
…honGH-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>
  • Loading branch information
barneygale and AlexWaygood committed May 29, 2023
1 parent 39f6a04 commit d593074
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Lib/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def __repr__(self):
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
Expand Down Expand Up @@ -715,6 +715,10 @@ def match(self, path_pattern, *, case_sensitive=None):
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.
Expand Down

0 comments on commit d593074

Please sign in to comment.