Skip to content

Commit ce6d8a4

Browse files
uranusjrichard26
andcommitted
Make 'dist' preparation as lazy as possible
This avoid an explicit requirement (name @ url) from being prepared too eagerly when its metadata is not required. Co-authored-by: Richard Si <[email protected]>
1 parent ec0c7ae commit ce6d8a4

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/pip/_internal/resolution/resolvelib/candidates.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import functools
12
import logging
23
import sys
34
from typing import TYPE_CHECKING, Any, FrozenSet, Iterable, Optional, Tuple, Union, cast
@@ -138,7 +139,6 @@ class exposes appropriate information to the resolver.
138139
found remote link (e.g. from pypi.org).
139140
"""
140141

141-
dist: BaseDistribution
142142
is_installed = False
143143

144144
def __init__(
@@ -156,7 +156,6 @@ def __init__(
156156
self._ireq = ireq
157157
self._name = name
158158
self._version = version
159-
self.dist = self._prepare()
160159
self._hash: Optional[int] = None
161160

162161
def __str__(self) -> str:
@@ -231,7 +230,8 @@ def _check_metadata_consistency(self, dist: BaseDistribution) -> None:
231230
except InvalidRequirement as e:
232231
raise MetadataInvalid(self._ireq, str(e))
233232

234-
def _prepare(self) -> BaseDistribution:
233+
@functools.cached_property
234+
def dist(self) -> BaseDistribution:
235235
try:
236236
dist = self._prepare_distribution()
237237
except HashError as e:

0 commit comments

Comments
 (0)