[Python-checkins] distutils2: Changed hashing behaviour for NormalizedVersion. Equal versions have the

tarek.ziade python-checkins at python.org
Sat Oct 2 00:52:19 CEST 2010


tarek.ziade pushed a4eaf904c096 to distutils2:

http://hg.python.org/distutils2/rev/a4eaf904c096
changeset:   701:a4eaf904c096
parent:      697:12c37807f046
user:        Amos Latteier <amos at latteier.com>
date:        Wed Sep 29 20:42:58 2010 -0400
summary:     Changed hashing behaviour for NormalizedVersion. Equal versions have the
files:       distutils2/tests/test_version.py, distutils2/version.py

diff --git a/distutils2/tests/test_version.py b/distutils2/tests/test_version.py
--- a/distutils2/tests/test_version.py
+++ b/distutils2/tests/test_version.py
@@ -31,6 +31,15 @@
         for v, s in self.versions:
             self.assertEqual(str(v), s)
 
+    def test_hash(self):
+
+        for v, s in self.versions:
+            self.assertEqual(hash(v), hash(V(s)))
+
+        versions = set([v for v,s in self.versions])
+        for v, s in self.versions:
+            self.assertIn(v, versions)
+
     def test_from_parts(self):
 
         for v, s in self.versions:
diff --git a/distutils2/version.py b/distutils2/version.py
--- a/distutils2/version.py
+++ b/distutils2/version.py
@@ -131,7 +131,7 @@
                        pad_zeros_length=0):
         """Parse 'N.N.N' sequences, return a list of ints.
 
-        @param s {str} 'N.N.N..." sequence to be parsed
+        @param s {str} 'N.N.N...' sequence to be parsed
         @param full_ver_str {str} The full version string from which this
             comes. Used for error strings.
         @param drop_trailing_zeros {bool} Whether to drop trailing zeros
@@ -206,7 +206,8 @@
         return self.__eq__(other) or self.__gt__(other)
 
     # See http://docs.python.org/reference/datamodel#object.__hash__
-    __hash__ = object.__hash__
+    def __hash__(self):
+        return hash(self.parts)
 
 
 def suggest_normalized_version(s):

--
Repository URL: http://hg.python.org/distutils2


More information about the Python-checkins mailing list