+ def __hash__(self):
+ if self.mbid is not None:
+ return hash(self.mbid)
+ else:
+ return id(self)
+
+ def __bool__(self): # empty name not possible for a valid obj
+ return bool(self.name)
+
+class Album(Meta):
+ """Info:
+ If a class that overrides __eq__() needs to retain the implementation of
+ __hash__() from a parent class, the interpreter must be told this explicitly
+ by setting __hash__ = <ParentClass>.__hash__.
+ """
+ __hash__ = Meta.__hash__
+
+ def __init__(self, **kwargs):
+ super().__init__(**kwargs)
+
+ def __eq__(self, other):
+ """
+ Perform mbid equality test if present,
+ else fallback on self.name equality
+ """
+ if hasattr(other, 'mbid'):
+ if other.mbid and self.mbid:
+ return self.mbid == other.mbid
+ return str(self) == str(other)
+
+ @property
+ def album(self):
+ return self.name
+