From 3e640e1e5b73699bcc6f310f5a6f27e0faea3dc8 Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Wed, 28 Apr 2010 21:56:01 +0200 Subject: [PATCH] Move eq method to imutable object parent class --- mopidy/models.py | 36 +++++++++--------------------------- 1 file changed, 9 insertions(+), 27 deletions(-) diff --git a/mopidy/models.py b/mopidy/models.py index 67b60840..d2b1e76a 100644 --- a/mopidy/models.py +++ b/mopidy/models.py @@ -23,6 +23,15 @@ class ImmutableObject(object): sum += hash(key) + hash(value) return sum + def __eq__(self, other): + if not isinstance(other, self.__class__): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + return not self.__eq__(other) + class Artist(ImmutableObject): """ @@ -38,15 +47,6 @@ class Artist(ImmutableObject): #: The artist name. Read-only. name = None - def __eq__(self, other): - if not isinstance(other, self.__class__): - return False - - return self.__dict__ == other.__dict__ - - def __ne__(self, other): - return not self.__eq__(other) - class Album(ImmutableObject): """ @@ -73,15 +73,6 @@ class Album(ImmutableObject): self._artists = frozenset(kwargs.pop('artists', [])) super(Album, self).__init__(*args, **kwargs) - def __eq__(self, other): - if not isinstance(other, self.__class__): - return False - - return self.__dict__ == other.__dict__ - - def __ne__(self, other): - return not self.__eq__(other) - @property def artists(self): """List of :class:`Artist` elements. Read-only.""" @@ -138,15 +129,6 @@ class Track(ImmutableObject): self._artists = frozenset(kwargs.pop('artists', [])) super(Track, self).__init__(*args, **kwargs) - def __eq__(self, other): - if not isinstance(other, self.__class__): - return False - - return self.__dict__ == other.__dict__ - - def __ne__(self, other): - return not self.__eq__(other) - @property def artists(self): """List of :class:`Artist`. Read-only."""