Skip to content

Commit ed4401a

Browse files
authored
Merge pull request #10282 from uranusjr/link-clean-result-3.6.0-compat
Move NameTuple method out of class
2 parents c18bc16 + 9b1bdf5 commit ed4401a

File tree

2 files changed

+27
-26
lines changed

2 files changed

+27
-26
lines changed

news/10280.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix 3.6.0 compatibility in link comparison logic.

src/pip/_internal/models/link.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -256,33 +256,33 @@ class _CleanResult(NamedTuple):
256256
subdirectory: str
257257
hashes: Dict[str, str]
258258

259-
@classmethod
260-
def from_link(cls, link: Link) -> "_CleanResult":
261-
parsed = link._parsed_url
262-
netloc = parsed.netloc.rsplit("@", 1)[-1]
263-
# According to RFC 8089, an empty host in file: means localhost.
264-
if parsed.scheme == "file" and not netloc:
265-
netloc = "localhost"
266-
fragment = urllib.parse.parse_qs(parsed.fragment)
267-
if "egg" in fragment:
268-
logger.debug("Ignoring egg= fragment in %s", link)
269-
try:
270-
# If there are multiple subdirectory values, use the first one.
271-
# This matches the behavior of Link.subdirectory_fragment.
272-
subdirectory = fragment["subdirectory"][0]
273-
except (IndexError, KeyError):
274-
subdirectory = ""
275-
# If there are multiple hash values under the same algorithm, use the
276-
# first one. This matches the behavior of Link.hash_value.
277-
hashes = {k: fragment[k][0] for k in _SUPPORTED_HASHES if k in fragment}
278-
return cls(
279-
parsed=parsed._replace(netloc=netloc, query="", fragment=""),
280-
query=urllib.parse.parse_qs(parsed.query),
281-
subdirectory=subdirectory,
282-
hashes=hashes,
283-
)
259+
260+
def _clean_link(link: Link) -> _CleanResult:
261+
parsed = link._parsed_url
262+
netloc = parsed.netloc.rsplit("@", 1)[-1]
263+
# According to RFC 8089, an empty host in file: means localhost.
264+
if parsed.scheme == "file" and not netloc:
265+
netloc = "localhost"
266+
fragment = urllib.parse.parse_qs(parsed.fragment)
267+
if "egg" in fragment:
268+
logger.debug("Ignoring egg= fragment in %s", link)
269+
try:
270+
# If there are multiple subdirectory values, use the first one.
271+
# This matches the behavior of Link.subdirectory_fragment.
272+
subdirectory = fragment["subdirectory"][0]
273+
except (IndexError, KeyError):
274+
subdirectory = ""
275+
# If there are multiple hash values under the same algorithm, use the
276+
# first one. This matches the behavior of Link.hash_value.
277+
hashes = {k: fragment[k][0] for k in _SUPPORTED_HASHES if k in fragment}
278+
return _CleanResult(
279+
parsed=parsed._replace(netloc=netloc, query="", fragment=""),
280+
query=urllib.parse.parse_qs(parsed.query),
281+
subdirectory=subdirectory,
282+
hashes=hashes,
283+
)
284284

285285

286286
@functools.lru_cache(maxsize=None)
287287
def links_equivalent(link1: Link, link2: Link) -> bool:
288-
return _CleanResult.from_link(link1) == _CleanResult.from_link(link2)
288+
return _clean_link(link1) == _clean_link(link2)

0 commit comments

Comments
 (0)