Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
bpo-24132: Fix validity of inter-path comparison in pathlib
Fix _BasePurePath comparison operators so that all of the new
path classes in pathlib are comparable with one another and return
results that are consistent with the existing behavoir, i.e.
Path('/') == PurePath('/').
  • Loading branch information
kfollstad committed May 28, 2021
commit d15d8da8ebb3d23934f2ca476d063cee0480f863
10 changes: 5 additions & 5 deletions Lib/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ def _cparts(self):
return self._cached_cparts

def __eq__(self, other):
if not isinstance(other, self.__class__):
if not isinstance(other, _PurePathBase):
return NotImplemented
return (
self._cparts == other._cparts
Expand All @@ -676,31 +676,31 @@ def __hash__(self):

def __lt__(self, other):
if (
not isinstance(other, self.__class__)
not isinstance(other, _PurePathBase)
or self._flavour is not other._flavour
):
return NotImplemented
return self._cparts < other._cparts

def __le__(self, other):
if (
not isinstance(other, self.__class__)
not isinstance(other, _PurePathBase)
or self._flavour is not other._flavour
):
return NotImplemented
return self._cparts <= other._cparts

def __gt__(self, other):
if (
not isinstance(other, self.__class__)
not isinstance(other, _PurePathBase)
or self._flavour is not other._flavour
):
return NotImplemented
return self._cparts > other._cparts

def __ge__(self, other):
if (
not isinstance(other, self.__class__)
not isinstance(other, _PurePathBase)
or self._flavour is not other._flavour
):
return NotImplemented
Expand Down