From 032f4379d9115e29fdf0aa5264f15c64aa4bb09a Mon Sep 17 00:00:00 2001 From: Andreas Poehlmann Date: Sun, 3 Mar 2024 12:57:00 +0100 Subject: [PATCH] Fix __eq__ _cparts missing (#203) * tests: add test to check for broken _cparts __eq__ * upath: add UPath._cparts fallback for __eq__ on py<312 --- upath/core.py | 5 +++++ upath/tests/test_core.py | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/upath/core.py b/upath/core.py index bea2eba..ec0a575 100644 --- a/upath/core.py +++ b/upath/core.py @@ -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): diff --git a/upath/tests/test_core.py b/upath/tests/test_core.py index d9a42d6..71a53ae 100644 --- a/upath/tests/test_core.py +++ b/upath/tests/test_core.py @@ -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", [