From 36cddad8cb4ba9be9931adaa32dc777922d0c718 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <h.tomwoerden@indiscale.com> Date: Tue, 15 Nov 2022 15:33:44 +0100 Subject: [PATCH] MAINT: some clean up --- src/caoscrawler/identifiable.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/caoscrawler/identifiable.py b/src/caoscrawler/identifiable.py index 78dfe08f..dd6491ea 100644 --- a/src/caoscrawler/identifiable.py +++ b/src/caoscrawler/identifiable.py @@ -88,6 +88,7 @@ class Identifiable(): def _create_hashable_string(identifiable: Identifiable) -> str: """ creates a string from the attributes of an identifiable that can be hashed + String has the form "P<parent>N<name>a:5b:10" """ rec_string = "P<{}>N<{}>".format(identifiable.record_type, identifiable.name) # TODO this structure neglects Properties if multiple exist for the same name @@ -100,18 +101,16 @@ class Identifiable(): """ Identifiables are equal if they belong to the same Record. Since ID and path are on their own enough to identify the Record it is sufficient if those attributes are equal. + 1. both IDs are set (not None) -> equal if IDs are equal + 2. both paths are set (not None) -> equal if paths are equal + 3. equal if attribute representations are equal """ if not isinstance(other, Identifiable): - return False - if self.record_id is not None and self.record_id == other.record_id: - return True - elif (self.record_id is not None and other.record_id is not None - and self.record_id == other.record_id): - return False - elif self.path is not None and self.path == other.path: - return True - elif (self.path is not None and other.path is not None and self.path == other.id): - return False + raiser ValueError("Identifiable can only be compared to other Identifiable objects.") + elif self.record_id is not None and other.record_id is not None: + return self.record_id == other.record_id + elif self.path is not None and other.path is not None: + return self.path == other.path elif self.get_representation() == other.get_representation(): return True else: -- GitLab