Implement equality on candidate classes

This commit is contained in:
Tzu-ping Chung 2020-04-04 15:17:56 +08:00
parent 327a31536f
commit 018c051a8e
1 changed files with 22 additions and 0 deletions

View File

@ -282,6 +282,17 @@ class AlreadyInstalledCandidate(Candidate):
distribution=self.dist,
)
def __eq__(self, other):
# type: (Any) -> bool
if isinstance(other, self.__class__):
return self.name == other.name and self.version == other.version
return False
# Needed for Python 2, which does not implement this by default
def __ne__(self, other):
# type: (Any) -> bool
return not self.__eq__(other)
@property
def name(self):
# type: () -> str
@ -345,6 +356,17 @@ class ExtrasCandidate(Candidate):
extras=self.extras,
)
def __eq__(self, other):
# type: (Any) -> bool
if isinstance(other, self.__class__):
return self.base == other.base and self.extras == other.extras
return False
# Needed for Python 2, which does not implement this by default
def __ne__(self, other):
# type: (Any) -> bool
return not self.__eq__(other)
@property
def name(self):
# type: () -> str