Skip to content

Commit

Permalink
Merge pull request #7994 from uranusjr/new-resolver-model-repr
Browse files Browse the repository at this point in the history
Add __repr__ to requirement/candidate models
  • Loading branch information
pfmoore committed Apr 7, 2020
2 parents 2b3d0a5 + 6d40804 commit 451f5d9
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/pip/_internal/resolution/resolvelib/candidates.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ def __init__(
self._version = version
self._dist = None # type: Optional[Distribution]

def __repr__(self):
# type: () -> str
return "{class_name}({link!r})".format(
class_name=self.__class__.__name__,
link=str(self.link),
)

def __eq__(self, other):
# type: (Any) -> bool
if isinstance(other, self.__class__):
Expand Down Expand Up @@ -259,6 +266,13 @@ def __init__(
skip_reason = "already satisfied"
factory.preparer.prepare_installed_requirement(self._ireq, skip_reason)

def __repr__(self):
# type: () -> str
return "{class_name}({distribution!r})".format(
class_name=self.__class__.__name__,
distribution=self.dist,
)

@property
def name(self):
# type: () -> str
Expand Down Expand Up @@ -314,6 +328,14 @@ def __init__(
self.base = base
self.extras = extras

def __repr__(self):
# type: () -> str
return "{class_name}(base={base!r}, extras={extras!r})".format(
class_name=self.__class__.__name__,
base=self.base,
extras=self.extras,
)

@property
def name(self):
# type: () -> str
Expand Down
21 changes: 21 additions & 0 deletions src/pip/_internal/resolution/resolvelib/requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ def __init__(self, candidate):
# type: (Candidate) -> None
self.candidate = candidate

def __repr__(self):
# type: () -> str
return "{class_name}({candidate!r})".format(
class_name=self.__class__.__name__,
candidate=self.candidate,
)

@property
def name(self):
# type: () -> str
Expand All @@ -43,6 +50,13 @@ def __init__(self, name):
# type: (str) -> None
self._name = name

def __repr__(self):
# type: () -> str
return "{class_name}(name={name!r})".format(
class_name=self.__class__.__name__,
name=self._name,
)

@property
def name(self):
# type: () -> str
Expand All @@ -65,6 +79,13 @@ def __init__(self, ireq, factory):
self._factory = factory
self.extras = ireq.req.extras

def __repr__(self):
# type: () -> str
return "{class_name}({requirement!r})".format(
class_name=self.__class__.__name__,
requirement=str(self._ireq.req),
)

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

0 comments on commit 451f5d9

Please sign in to comment.