Repository: ros-infrastructure/catkin_pkg

Issue:
Dependency should have a hash function
Although they are not immutable, this is important for being able to deduplicate/manage them using `set()`. I'm monkey-patching in this one, but it'd be great to have it merge upstream:

```
import catkin_pkg.package
catkin_pkg.package.Dependency.__hash__ = lambda self: hash(tuple([getattr(self, slot) for slot in self.__slots__]))
```

Discussion:

Patch:
diff --git a/src/catkin_pkg/package.py b/src/catkin_pkg/package.py
index f7e0717..0cfce13 100644
--- a/src/catkin_pkg/package.py
+++ b/src/catkin_pkg/package.py
@@ -262,6 +262,9 @@ class Dependency(object):
             return False
         return all([getattr(self, attr) == getattr(other, attr) for attr in self.__slots__])
 
+    def __hash__(self):
+        return hash(tuple([getattr(self, slot) for slot in self.__slots__]))
+
     def __str__(self):
         return self.name
 


Test patch:
diff --git a/test/test_package.py b/test/test_package.py
index 527f5b0..850d515 100644
--- a/test/test_package.py
+++ b/test/test_package.py
@@ -59,6 +59,26 @@ class PackageTest(unittest.TestCase):
         self.assertEquals(5, dep.version_gt)
         self.assertRaises(TypeError, Dependency, 'foo', unknownattribute=42)
 
+        d = {}
+        d[dep] = None
+        dep2 = Dependency('foo',
+                          version_lt=1,
+                          version_lte=2,
+                          version_eq=3,
+                          version_gte=4,
+                          version_gt=5)
+        d[dep2] = None
+        self.assertEquals(len(d), 1)
+        dep3 = Dependency('foo',
+                          version_lt=1,
+                          version_lte=2,
+                          version_eq=3,
+                          version_gte=4,
+                          version_gt=6)
+        d[dep3] = None
+        self.assertEquals(len(d), 2)
+
+
     def test_init_kwargs_string(self):
         pack = Package('foo',
                        name='bar',