|
5 | 5 |
|
6 | 6 | from pip._internal.req.constructors import install_req_drop_extras
|
7 | 7 | from pip._internal.req.req_install import InstallRequirement
|
8 |
| -from pip._internal.utils.models import KeyBasedCompareMixin |
9 | 8 |
|
10 | 9 | from .base import Candidate, CandidateLookup, Requirement, format_name
|
11 | 10 |
|
@@ -48,21 +47,26 @@ def is_satisfied_by(self, candidate: Candidate) -> bool:
|
48 | 47 | return candidate == self.candidate
|
49 | 48 |
|
50 | 49 |
|
51 |
| -class SpecifierRequirement(Requirement, KeyBasedCompareMixin): |
| 50 | +class SpecifierRequirement(Requirement): |
52 | 51 | def __init__(self, ireq: InstallRequirement) -> None:
|
53 | 52 | assert ireq.link is None, "This is a link, not a specifier"
|
54 | 53 | self._ireq = ireq
|
55 | 54 | self._extras = frozenset(canonicalize_name(e) for e in self._ireq.extras)
|
56 |
| - KeyBasedCompareMixin.__init__( |
57 |
| - self, key=str(ireq), defining_class=SpecifierRequirement |
58 |
| - ) |
59 | 55 |
|
60 | 56 | def __str__(self) -> str:
|
61 | 57 | return str(self._ireq.req)
|
62 | 58 |
|
63 | 59 | def __repr__(self) -> str:
|
64 | 60 | return f"{self.__class__.__name__}({str(self._ireq.req)!r})"
|
65 | 61 |
|
| 62 | + def __eq__(self, other: object) -> bool: |
| 63 | + if not isinstance(other, SpecifierRequirement): |
| 64 | + return NotImplemented |
| 65 | + return str(self._ireq) == str(other._ireq) |
| 66 | + |
| 67 | + def __hash__(self) -> int: |
| 68 | + return hash(str(self._ireq)) |
| 69 | + |
66 | 70 | @property
|
67 | 71 | def project_name(self) -> NormalizedName:
|
68 | 72 | assert self._ireq.req, "Specifier-backed ireq is always PEP 508"
|
@@ -111,9 +115,14 @@ def __init__(self, ireq: InstallRequirement) -> None:
|
111 | 115 | assert ireq.link is None, "This is a link, not a specifier"
|
112 | 116 | self._ireq = install_req_drop_extras(ireq)
|
113 | 117 | self._extras = frozenset(canonicalize_name(e) for e in self._ireq.extras)
|
114 |
| - KeyBasedCompareMixin.__init__( |
115 |
| - self, key=str(ireq), defining_class=SpecifierRequirement |
116 |
| - ) |
| 118 | + |
| 119 | + def __eq__(self, other: object) -> bool: |
| 120 | + if not isinstance(other, SpecifierWithoutExtrasRequirement): |
| 121 | + return NotImplemented |
| 122 | + return str(self._ireq) == str(other._ireq) |
| 123 | + |
| 124 | + def __hash__(self) -> int: |
| 125 | + return hash(str(self._ireq)) |
117 | 126 |
|
118 | 127 |
|
119 | 128 | class RequiresPythonRequirement(Requirement):
|
@@ -165,21 +174,26 @@ def is_satisfied_by(self, candidate: Candidate) -> bool:
|
165 | 174 | return self.specifier.contains(candidate.version, prereleases=True)
|
166 | 175 |
|
167 | 176 |
|
168 |
| -class UnsatisfiableRequirement(Requirement, KeyBasedCompareMixin): |
| 177 | +class UnsatisfiableRequirement(Requirement): |
169 | 178 | """A requirement that cannot be satisfied."""
|
170 | 179 |
|
171 | 180 | def __init__(self, name: NormalizedName) -> None:
|
172 | 181 | self._name = name
|
173 |
| - KeyBasedCompareMixin.__init__( |
174 |
| - self, key=str(name), defining_class=UnsatisfiableRequirement |
175 |
| - ) |
176 | 182 |
|
177 | 183 | def __str__(self) -> str:
|
178 | 184 | return f"{self._name} (unavailable)"
|
179 | 185 |
|
180 | 186 | def __repr__(self) -> str:
|
181 | 187 | return f"{self.__class__.__name__}({str(self._name)!r})"
|
182 | 188 |
|
| 189 | + def __eq__(self, other: object) -> bool: |
| 190 | + if not isinstance(other, UnsatisfiableRequirement): |
| 191 | + return NotImplemented |
| 192 | + return self._name == other._name |
| 193 | + |
| 194 | + def __hash__(self) -> int: |
| 195 | + return hash(self._name) |
| 196 | + |
183 | 197 | @property
|
184 | 198 | def project_name(self) -> NormalizedName:
|
185 | 199 | return self._name
|
|
0 commit comments