Assume I have some complex class structure with some hierarchy, public and private fields.
I need to do some custom serialization for such class. In some test after deserialize I want to compare entities of original object and deserialized one. But since serialization is custom – some fields could differ. For example
class A:
def __init__(self):
self.a = 0
self.b = 1
def __eq__(self, other_deserialized):
return self.a == other_deserialized.a
So in context of serialization objects are equal because field ‘a’ are equal ( that only thing I interested in serialization). But in some other context I wish to compare objects by all fields so I would want to have
class A:
def __init__(self):
self.a = 0
self.b = 1
def __eq__(self, other):
return (self.a == other.a) and (self.b == other.b)
So looks like I need to custome equality operator for such purposes. Is there some elegance way to solve this?