Skip to content

Commit

Permalink
review comment: renamed and moved up ExtrasCandidate._ireq
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderr committed Sep 6, 2023
1 parent 4e73e3e commit 50cd318
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
9 changes: 5 additions & 4 deletions src/pip/_internal/resolution/resolvelib/candidates.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,10 +427,11 @@ def __init__(
self,
base: BaseCandidate,
extras: FrozenSet[str],
ireq: Optional[InstallRequirement] = None,
*,
comes_from: Optional[InstallRequirement] = None,
) -> None:
"""
:param ireq: the InstallRequirement that led to this candidate, if it
:param ireq: the InstallRequirement that led to this candidate if it
differs from the base's InstallRequirement. This will often be the
case in the sense that this candidate's requirement has the extras
while the base's does not. Unlike the InstallRequirement backed
Expand All @@ -439,7 +440,7 @@ def __init__(
"""
self.base = base
self.extras = extras
self._ireq = ireq
self._comes_from = comes_from if comes_from is not None else self.base._ireq

def __str__(self) -> str:
name, rest = str(self.base).split(" ", 1)
Expand Down Expand Up @@ -514,7 +515,7 @@ def iter_dependencies(self, with_requires: bool) -> Iterable[Optional[Requiremen
for r in self.base.dist.iter_dependencies(valid_extras):
yield from factory.make_requirements_from_spec(
str(r),
self._ireq if self._ireq is not None else self.base._ireq,
self._comes_from,
valid_extras,
)

Expand Down
9 changes: 5 additions & 4 deletions src/pip/_internal/resolution/resolvelib/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,14 @@ def _make_extras_candidate(
self,
base: BaseCandidate,
extras: FrozenSet[str],
ireq: Optional[InstallRequirement] = None,
*,
comes_from: Optional[InstallRequirement] = None,
) -> ExtrasCandidate:
cache_key = (id(base), extras)
try:
candidate = self._extras_candidate_cache[cache_key]
except KeyError:
candidate = ExtrasCandidate(base, extras, ireq=ireq)
candidate = ExtrasCandidate(base, extras, comes_from=comes_from)
self._extras_candidate_cache[cache_key] = candidate
return candidate

Expand All @@ -165,7 +166,7 @@ def _make_candidate_from_dist(
self._installed_candidate_cache[dist.canonical_name] = base
if not extras:
return base
return self._make_extras_candidate(base, extras, ireq=template)
return self._make_extras_candidate(base, extras, comes_from=template)

def _make_candidate_from_link(
self,
Expand Down Expand Up @@ -227,7 +228,7 @@ def _make_candidate_from_link(

if not extras:
return base
return self._make_extras_candidate(base, extras, ireq=template)
return self._make_extras_candidate(base, extras, comes_from=template)

def _iter_found_candidates(
self,
Expand Down

0 comments on commit 50cd318

Please sign in to comment.