Skip to content
Snippets Groups Projects
Commit 36cddad8 authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

MAINT: some clean up

parent 6055192a
Branches
Tags
3 merge requests!91Release 0.3,!69Refactor Identifiable and caches,!67MAINT: introduce an identifiable class
Pipeline #30542 failed
...@@ -88,6 +88,7 @@ class Identifiable(): ...@@ -88,6 +88,7 @@ class Identifiable():
def _create_hashable_string(identifiable: Identifiable) -> str: def _create_hashable_string(identifiable: Identifiable) -> str:
""" """
creates a string from the attributes of an identifiable that can be hashed 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) rec_string = "P<{}>N<{}>".format(identifiable.record_type, identifiable.name)
# TODO this structure neglects Properties if multiple exist for the same name # TODO this structure neglects Properties if multiple exist for the same name
...@@ -100,18 +101,16 @@ class Identifiable(): ...@@ -100,18 +101,16 @@ class Identifiable():
""" """
Identifiables are equal if they belong to the same Record. Since ID and path are on their 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. 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): if not isinstance(other, Identifiable):
return False raiser ValueError("Identifiable can only be compared to other Identifiable objects.")
if self.record_id is not None and self.record_id == other.record_id: elif self.record_id is not None and other.record_id is not None:
return True return self.record_id == other.record_id
elif (self.record_id is not None and other.record_id is not None elif self.path is not None and other.path is not None:
and self.record_id == other.record_id): return self.path == other.path
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
elif self.get_representation() == other.get_representation(): elif self.get_representation() == other.get_representation():
return True return True
else: else:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment