From 70e44c3a0f42145835e34386ae04e173c9865489 Mon Sep 17 00:00:00 2001 From: "Adam D. Barratt" Date: Sun, 4 Sep 2011 16:36:40 +0000 Subject: [PATCH] migrationitem: add support for using items as indexes in to lists In order to provide the support, items may now be tested for equality and hashed. Two items are considered equal if they have the same unversioned name (and version, if appropriate); hashing is based on a tuple hash of the name and version. Signed-off-by: Adam D. Barratt --- migrationitem.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/migrationitem.py b/migrationitem.py index 67e5efd..baa606e 100644 --- a/migrationitem.py +++ b/migrationitem.py @@ -29,6 +29,19 @@ class MigrationItem: else: return self.uvname + def __eq__(self, other): + isequal = False + if self.uvname == other.uvname: + if self.version is None or other.version is None: + isequal = True + else: + isequal = self.version == other.version + + return isequal + + def __hash__(self): + return hash((self.uvname, self.version)) + def _get_name(self): return self._name