diff --git a/src/caoscrawler/identifiable.py b/src/caoscrawler/identifiable.py index 78dfe08f92b9975668f6d7b290a92fe3d1f71730..dd6491eafec64a9309513f2a2cf573f1b62314b7 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: