Skip to content

Commit 032f437

Browse files
authored
Fix __eq__ _cparts missing (#203)
* tests: add test to check for broken _cparts __eq__ * upath: add UPath._cparts fallback for __eq__ on py<312
1 parent 8f8ca48 commit 032f437

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

upath/core.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,11 @@ def _parts(self):
516516
def _parts(self, value):
517517
self.__parts = value
518518

519+
@property
520+
def _cparts(self):
521+
# required for pathlib.Path.__eq__ compatibility on Python <3.12
522+
return self.parts
523+
519524
# === pathlib.PurePath ============================================
520525

521526
def __reduce__(self):

upath/tests/test_core.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,13 @@ def test_copy_path_append():
248248
assert str(path / "folder2" / "folder3") == str(copy_path)
249249

250250

251+
def test_compare_to_pathlib_path_ne():
252+
assert UPath("gcs://bucket/folder") != pathlib.Path("gcs://bucket/folder")
253+
assert pathlib.Path("gcs://bucket/folder") != UPath("gcs://bucket/folder")
254+
assert UPath("/bucket/folder") == pathlib.Path("/bucket/folder")
255+
assert pathlib.Path("/bucket/folder") == UPath("/bucket/folder")
256+
257+
251258
@pytest.mark.parametrize(
252259
"urlpath",
253260
[

0 commit comments

Comments
 (0)