Skip to content

Commit cb06334

Browse files
committed
[base] Move comparison to Smartlist
1 parent 250f17d commit cb06334

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

odml/base.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ def __eq__(self, obj):
2323
Do a deep comparison of this object and its odml properties.
2424
The 'id' attribute of an object is excluded, since it is
2525
unique within a document.
26-
SmartList attributes of 'sections' and 'properties' are
27-
handled specially: We want to make sure that the lists'
28-
objects are properly compared without changing the order
29-
of the individual lists.
3026
"""
3127
# cannot compare totally different stuff
3228
if not isinstance(self, obj.__class__):
@@ -35,14 +31,6 @@ def __eq__(self, obj):
3531
for key in self._format:
3632
if key == "id" or key == "oid":
3733
continue
38-
elif (isinstance(getattr(self, key), SmartList) and
39-
sorted(getattr(self, key), key=lambda x: x.name) !=
40-
sorted(getattr(obj, key), key=lambda x: x.name)):
41-
# This special case was introduced only due to the fact
42-
# that RDF files will be loaded with randomized list
43-
# order. With any other file format the list order
44-
# remains unchanged.
45-
return False
4634
elif getattr(self, key) != getattr(obj, key):
4735
return False
4836

@@ -143,6 +131,28 @@ def __contains__(self, key):
143131
if (hasattr(obj, "name") and obj.name == key) or key == obj:
144132
return True
145133

134+
def __eq__(self, obj):
135+
"""
136+
SmartList attributes of 'sections' and 'properties' are
137+
handled specially: We want to make sure that the lists'
138+
objects are properly compared without changing the order
139+
of the individual lists.
140+
"""
141+
# This special case was introduced only due to the fact
142+
# that RDF files will be loaded with randomized list
143+
# order. With any other file format the list order
144+
# remains unchanged.
145+
if sorted(self, key=lambda x: x.name) != sorted(obj, key=lambda x: x.name):
146+
return False
147+
148+
return True
149+
150+
def __ne__(self, obj):
151+
"""
152+
Use the __eq__ function to determine if both objects are equal
153+
"""
154+
return not self == obj
155+
146156
def index(self, obj):
147157
"""
148158
Find obj in list

0 commit comments

Comments
 (0)