8000 bpo-24132: Direct sub-classing of pathlib.Path by kfollstad · Pull Request #26438 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-24132: Direct sub-classing of pathlib.Path #26438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 11 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

8000
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
0