diff --git a/src/univers/gem.py b/src/univers/gem.py index b59d32aa..cbd47f7c 100644 --- a/src/univers/gem.py +++ b/src/univers/gem.py @@ -225,7 +225,7 @@ def equal_strictly(self, other): return self.version == other.version def __hash__(self): - return hash(self.canonical_segments) + return hash(tuple(self.canonical_segments)) def __eq__(self, other): return self.canonical_segments == other.canonical_segments @@ -321,7 +321,7 @@ def get_segments(self): def canonical_segments(self): if not self._canonical_segments: self._canonical_segments = self.get_canonical_segments() - return list(self._canonical_segments) + return tuple(self._canonical_segments) def get_canonical_segments(self): """ diff --git a/tests/test_rubygems_gem_version.py b/tests/test_rubygems_gem_version.py index 6c14a00d..63c27f44 100644 --- a/tests/test_rubygems_gem_version.py +++ b/tests/test_rubygems_gem_version.py @@ -181,9 +181,13 @@ def test_split_segments(): def test_canonical_segments(): - assert GemVersion("1.0.0").canonical_segments == [1] - assert GemVersion("1.0.0.a.1.0").canonical_segments == [1, "a", 1] - assert GemVersion("1.2.3-1").canonical_segments == [1, 2, 3, "pre", 1] + assert GemVersion("1.0.0").canonical_segments == (1,) + assert GemVersion("1.0.0.a.1.0").canonical_segments == (1, "a", 1) + assert GemVersion("1.2.3-1").canonical_segments == (1, 2, 3, "pre", 1) + + +def test_GemVersion_is_hashable(): + hash(GemVersion("1.0.0")) def test_frozen_version():