Skip to content

Commit

Permalink
Fix __eq__ _cparts missing (#203)
Browse files Browse the repository at this point in the history
* tests: add test to check for broken _cparts __eq__
* upath: add UPath._cparts fallback for __eq__ on py<312
  • Loading branch information
ap-- authored Mar 3, 2024
1 parent 8f8ca48 commit 032f437
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions upath/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,11 @@ def _parts(self):
def _parts(self, value):
self.__parts = value

@property
def _cparts(self):
# required for pathlib.Path.__eq__ compatibility on Python <3.12
return self.parts

# === pathlib.PurePath ============================================

def __reduce__(self):
Expand Down
7 changes: 7 additions & 0 deletions upath/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,13 @@ def test_copy_path_append():
assert str(path / "folder2" / "folder3") == str(copy_path)


def test_compare_to_pathlib_path_ne():
assert UPath("gcs://bucket/folder") != pathlib.Path("gcs://bucket/folder")
assert pathlib.Path("gcs://bucket/folder") != UPath("gcs://bucket/folder")
assert UPath("/bucket/folder") == pathlib.Path("/bucket/folder")
assert pathlib.Path("/bucket/folder") == UPath("/bucket/folder")


@pytest.mark.parametrize(
"urlpath",
[
Expand Down

0 comments on commit 032f437

Please sign in to comment.