diff options
| author | Amos Latteier <amos@latteier.com> | 2010-09-29 20:42:58 -0400 |
|---|---|---|
| committer | Amos Latteier <amos@latteier.com> | 2010-09-29 20:42:58 -0400 |
| commit | d37168c63fc520585a347f03701d5ddad41a09bd (patch) | |
| tree | 31c66746bc36732ea04c19dbb0b58b278a970866 /distutils2 | |
| parent | 89ec282598e76078695677eec5db4c0f1ed70d50 (diff) | |
| download | disutils2-d37168c63fc520585a347f03701d5ddad41a09bd.tar.gz | |
Changed hashing behaviour for NormalizedVersion. Equal versions have the
same hash now. This is my understanding of what should happen given the info
at http://docs.python.org/reference/datamodel#object.__hash__
Also added tests for hashing.
Also fixed a nit in a doc string that made emacs colorize versions.py
incorrectly.
Diffstat (limited to 'distutils2')
| -rw-r--r-- | distutils2/tests/test_version.py | 9 | ||||
| -rw-r--r-- | distutils2/version.py | 5 |
2 files changed, 12 insertions, 2 deletions
diff --git a/distutils2/tests/test_version.py b/distutils2/tests/test_version.py index 1e392f2..35d0710 100644 --- a/distutils2/tests/test_version.py +++ b/distutils2/tests/test_version.py @@ -31,6 +31,15 @@ class VersionTestCase(unittest.TestCase): 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 index 64c33f7..830c0eb 100644 --- a/distutils2/version.py +++ b/distutils2/version.py @@ -131,7 +131,7 @@ class NormalizedVersion(object): 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 @@ class NormalizedVersion(object): 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): |
