Skip to content

Commit

Permalink
Merge pull request #98 from ziadhany/gem-fix
Browse files Browse the repository at this point in the history
Fix : GemVersion TypeError unhashable type: 'list'
  • Loading branch information
TG1999 authored Feb 10, 2023
2 parents a8ec2e7 + bf190c1 commit 053dfc1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/univers/gem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
"""
Expand Down
10 changes: 7 additions & 3 deletions tests/test_rubygems_gem_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit 053dfc1

Please sign in to comment.