Skip to content

New Resolver: Implement equality on candidate classes #7976

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/pip/_internal/resolution/resolvelib/candidates.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,17 @@ def __repr__(self):
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
Expand Down Expand Up @@ -345,6 +356,17 @@ def __repr__(self):
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I legit don't wanna wait.

def __ne__(self, other):
# type: (Any) -> bool
return not self.__eq__(other)

@property
def name(self):
# type: () -> str
Expand Down Expand Up @@ -398,6 +420,10 @@ def __init__(self, py_version_info):
version_info = sys.version_info[:3]
self._version = Version(".".join(str(c) for c in version_info))

# We don't need to implement __eq__() and __ne__() since there is always
# only one RequiresPythonCandidate in a resolution, i.e. the host Python.
# The built-in object.__eq__() and object.__ne__() do exactly what we want.

@property
def name(self):
# type: () -> str
Expand Down