Skip to content

Commit 8cca170

Browse files
authored
Merge pull request #7976 from uranusjr/installed-candidate-equal
New Resolver: Implement equality on candidate classes
2 parents 9cbe8fb + 591d476 commit 8cca170

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/pip/_internal/resolution/resolvelib/candidates.py

+26
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,17 @@ def __repr__(self):
288288
distribution=self.dist,
289289
)
290290

291+
def __eq__(self, other):
292+
# type: (Any) -> bool
293+
if isinstance(other, self.__class__):
294+
return self.name == other.name and self.version == other.version
295+
return False
296+
297+
# Needed for Python 2, which does not implement this by default
298+
def __ne__(self, other):
299+
# type: (Any) -> bool
300+
return not self.__eq__(other)
301+
291302
@property
292303
def name(self):
293304
# type: () -> str
@@ -351,6 +362,17 @@ def __repr__(self):
351362
extras=self.extras,
352363
)
353364

365+
def __eq__(self, other):
366+
# type: (Any) -> bool
367+
if isinstance(other, self.__class__):
368+
return self.base == other.base and self.extras == other.extras
369+
return False
370+
371+
# Needed for Python 2, which does not implement this by default
372+
def __ne__(self, other):
373+
# type: (Any) -> bool
374+
return not self.__eq__(other)
375+
354376
@property
355377
def name(self):
356378
# type: () -> str
@@ -404,6 +426,10 @@ def __init__(self, py_version_info):
404426
version_info = sys.version_info[:3]
405427
self._version = Version(".".join(str(c) for c in version_info))
406428

429+
# We don't need to implement __eq__() and __ne__() since there is always
430+
# only one RequiresPythonCandidate in a resolution, i.e. the host Python.
431+
# The built-in object.__eq__() and object.__ne__() do exactly what we want.
432+
407433
@property
408434
def name(self):
409435
# type: () -> str

0 commit comments

Comments
 (0)