Skip to content

Commit

Permalink
specifiers: don't rely on hashes for equality (#284)
Browse files Browse the repository at this point in the history
  • Loading branch information
xavfernandez committed Mar 27, 2020
1 parent 20a9a33 commit ed0a58f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packaging/specifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,14 @@ def __str__(self):
# type: () -> str
return "{0}{1}".format(*self._spec)

@property
def _canonical_spec(self):
# type: () -> Tuple[str, Union[Version, str]]
return self._spec[0], canonicalize_version(self._spec[1])

def __hash__(self):
# type: () -> int
operator, version = self._spec
return hash((operator, canonicalize_version(version)))
return hash(self._canonical_spec)

def __eq__(self, other):
# type: (object) -> bool
Expand All @@ -148,7 +152,7 @@ def __eq__(self, other):
elif not isinstance(other, self.__class__):
return NotImplemented

return hash(self) == hash(other)
return self._canonical_spec == other._canonical_spec

def __ne__(self, other):
# type: (object) -> bool
Expand Down

0 comments on commit ed0a58f

Please sign in to comment.