1
1
Fork 0
mirror of https://github.com/pypa/pip synced 2023-12-13 21:30:23 +01:00

Add __repr__ to requirement/candidate models

This commit is contained in:
Tzu-ping Chung 2020-04-07 20:53:25 +08:00
parent 2b3d0a5cc0
commit 6d40804b12
2 changed files with 43 additions and 0 deletions

View file

@ -110,6 +110,13 @@ class _InstallRequirementBackedCandidate(Candidate):
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__):
@ -259,6 +266,13 @@ class AlreadyInstalledCandidate(Candidate):
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
@ -314,6 +328,14 @@ class ExtrasCandidate(Candidate):
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

View file

@ -18,6 +18,13 @@ class ExplicitRequirement(Requirement):
# 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
@ -43,6 +50,13 @@ class NoMatchRequirement(Requirement):
# 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
@ -65,6 +79,13 @@ class SpecifierRequirement(Requirement):
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