Repository: pypa/pip
File: src/pip/_internal/models/link.py (Python)

Code before:
    """
    Make sure a link is fully quoted.
    For example, if ' ' occurs in the URL, it will be replaced with "%20",
    and without double-quoting other characters.
    """
    # Split the URL into parts according to the general structure
    # `scheme://netloc/path?query#fragment`.
    result = urllib.parse.urlsplit(url)
    # If the netloc is empty, then the URL refers to a local filesystem path.
    is_local_path = not result.netloc
    path = _clean_url_path(result.path, is_local_path=is_local_path)
    return urllib.parse.urlunsplit(result._replace(path=path))


def _absolute_link_url(base_url: str, file_url: str) -> str:
    """Return an absolute file URL from a simple response.

    If the file URL is already absolute, the function does nothing.
    If the file URL is relative, it is joined with the base URL.
    """
    # If the file URL is already absolute, joining it with the page URL
    # will do nothing. PyPI returns absolute URLs so we can avoid expensive
    # urljoin() calls in the common case. (It would be technically more
    # correct to parse the file URL and check if it has a scheme, but the
    # slow URL parsing urljoin() does is what we're trying to avoid in the
    # first place, so we only check for the http[s]:// prefix.)
    if file_url.startswith(("https://", "http://")):
        return file_url
    else:
        return urllib.parse.urljoin(base_url, file_url)


@functools.total_ordering
class Link:
    """Represents a parsed link from a Package Index's simple URL"""

    __slots__ = [
        "_parsed_url",
        "_url",
        "_path",
        "_hashes",
        "comes_from",
        "requires_python",
        "yanked_reason",
        "metadata_file_data",
        "cache_link_parsing",
        "egg_fragment",
    ]

    def __init__(
        self,

Review comment (suggestion):
@ichard26 I was indeed confused, thanks for the clarification.

Maybe a simpler comment like this would have helped my distracted self. What do you think?

```suggestion
def _absolute_link_url(base_url: str, url: str) -> str:
    """A faster implementation of urlib.parse.urljoin with a shortcut for absolute http/https URLs."""
```


Code after:
    """
    Make sure a link is fully quoted.
    For example, if ' ' occurs in the URL, it will be replaced with "%20",
    and without double-quoting other characters.
    """
    # Split the URL into parts according to the general structure
    # `scheme://netloc/path?query#fragment`.
    result = urllib.parse.urlsplit(url)
    # If the netloc is empty, then the URL refers to a local filesystem path.
    is_local_path = not result.netloc
    path = _clean_url_path(result.path, is_local_path=is_local_path)
    return urllib.parse.urlunsplit(result._replace(path=path))


def _absolute_link_url(base_url: str, url: str) -> str:
    """
    A faster implementation of urllib.parse.urljoin with a shortcut
    for absolute http/https URLs.
    """
    if url.startswith(("https://", "http://")):
        return url
    else:
        return urllib.parse.urljoin(base_url, url)


@functools.total_ordering
class Link:
    """Represents a parsed link from a Package Index's simple URL"""

    __slots__ = [
        "_parsed_url",
        "_url",
        "_path",
        "_hashes",
        "comes_from",
        "requires_python",
        "yanked_reason",
        "metadata_file_data",
        "cache_link_parsing",
        "egg_fragment",
    ]

    def __init__(
        self,
        url: str,
        comes_from: Optional[Union[str, "IndexContent"]] = None,
        requires_python: Optional[str] = None,
        yanked_reason: Optional[str] = None,
        metadata_file_data: Optional[MetadataFile] = None,
        cache_link_parsing: bool = True,
        hashes: Optional[Mapping[str, str]] = None,